forked from tstirrat/hammerspoon-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glensSpoons.lua
192 lines (156 loc) · 7.01 KB
/
glensSpoons.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
-- Global log level. Per-spoon log level can be configured in each Install:andUse block below.
hs.logger.defaultLogLevel = "info"
hs.loadSpoon("SpoonInstall")
-- This is just a shortcut to make the declarations below look more readable,
-- i.e. Install:andUse instead of spoon.SpoonInstall:andUse.
Install = spoon.SpoonInstall
-- I prefer sync notifications, makes them easier to read.
Install.use_syncinstall = true
windowChord = {"ctrl", "alt", "cmd"}
-- ########## Window and screen manipulation ##########
-- Could also just use the build-in 'layout' and/or 'grid' with their snap-to sizing, nudging, shrinking and expanding: https://www.hammerspoon.org/docs/hs.grid.html#setGrid
-- The WindowHalfsAndThirds spoon sets up multiple key bindings for manipulating the size and position of windows.
Install:andUse("WindowHalfsAndThirds",
{
config = {
use_frame_correctness = true
},
hotkeys = {
left_half = { hyper_left, "j" },
right_half = { hyper_left, ";" },
top_half = { hyper_left, "u" },
bottom_half = { hyper_left, "n" },
top_left = { hyper_left, "i" },
top_right = { hyper_left, "o" },
bottom_left = { hyper_left, "k" },
bottom_right = { hyper_left, "l" },
max_toggle = { hyper_left, "m" },
undo = { hyper_left, "z" },
center = { hyper_left, "," },
larger = { hyper_left, "6" },
smaller = { hyper_left, "v" },
-- Disable the following. They can be achieved with the above keys.
top_third = { {}, "F18" },
bottom_third = { {}, "F18" },
third_left = { {}, "F18" },
third_right = { {}, "F18" },
third_up = { {}, "F18" },
third_down = { {}, "F18" },
}
}
)
-- The WindowScreenLeftAndRight spoon sets up key bindings for moving windows between multiple screens.
Install:andUse("WindowScreenLeftAndRight",
{
hotkeys = 'default'
}
)
-- Windows manipulation.
Install:andUse("WinWin", {})
-- ########## Organization and Productivity ##########
-- The UniversalArchive spoon sets up a single key binding (Ctrl-Cmd-a) to archive the current item in Evernote,
-- Mail and Outlook.
--Install:andUse("UniversalArchive",
-- {
-- config = {
-- evernote_archive_notebook = ".Archive",
-- outlook_archive_folder = "Archive (diego.zamboni@swisscom.com)",
-- archive_notifications = false
-- },
-- hotkeys = { archive = { { "ctrl", "cmd" }, "a" } }
-- }
--)
-- Route URLs to different applications with pattern matching.
Install:andUse("URLDispatcher", {})
-- The EvernoteOpenAndTag spoon sets up some missing key bindings for note manipulation in Evernote.
--Install:andUse("EvernoteOpenAndTag",
-- {
-- hotkeys = {
-- open_note = { hyper, "o" },
-- ["open_and_tag-+work,+swisscom"] = { hyper, "w" },
-- ["open_and_tag-+personal"] = { hyper, "p" },
-- ["tag-@zzdone"] = { hyper, "z" }
-- }
-- }
--)
-- ########## System and UI ##########
-- The HSKeybindings spoon traverses the current application’s menus and builds a cheatsheet of the keyboard shortcuts,
-- showing it in a nice popup window.
--Install:andUse("HSKeybindings", {})
-- The KSheet spoon traverses the current application’s menus and builds a cheatsheet of the keyboard shortcuts,
-- showing it in a nice popup window.
Install:andUse("KSheet",
{
hotkeys = {
toggle = { hyper, "/" }
}
}
)
-- ########## Network transitions ##########
-- The WiFiTransitions spoon allows triggering arbitrary actions when the SSID changes. I am interested in the
-- change from my work network (corpnet01) to other networks, mainly because at work I need a proxy for all
-- connections to the Internet. I have two applications which don’t handle these transitions gracefully on their
-- own: Spotify and Adium. So I have written a couple of functions for helping them along.
-- The reconfigSpotifyProxy function quits Spotify, updates the proxy settings in its config file, and restarts it.
function reconfigSpotifyProxy(proxy)
local spotify = hs.appfinder.appFromName("Spotify")
local lastapp = nil
if spotify then
lastapp = hs.application.frontmostApplication()
spotify:kill()
hs.timer.usleep(40000)
end
-- hs.notify.show(string.format("Reconfiguring %sSpotify", ((spotify~=nil) and "and restarting " or "")), string.format("Proxy %s", (proxy and "enabled" or "disabled")), "")
-- I use CFEngine to reconfigure the Spotify preferences
cmd = string.format("/usr/local/bin/cf-agent -K -f %s/files/spotify-proxymode.cf%s", hs.configdir, (proxy and " -DPROXY" or " -DNOPROXY"))
output, status, t, rc = hs.execute(cmd)
if spotify and lastapp then
hs.timer.doAfter(3,
function()
if not hs.application.launchOrFocus("Spotify") then
hs.notify.show("Error launching Spotify", "", "")
end
if lastapp then
hs.timer.doAfter(0.5, hs.fnutils.partial(lastapp.activate, lastapp))
end
end)
end
end
-- The configuration for the WiFiTransitions spoon invoked these functions with the appropriate parameters.
Install:andUse("WiFiTransitions",
{
config = {
actions = {
-- { -- Test action just to see the SSID transitions
-- fn = function(_, _, prev_ssid, new_ssid)
-- hs.notify.show("SSID change", string.format("From '%s' to '%s'", prev_ssid, new_ssid), "")
-- end
-- },
{ -- Enable proxy in Spotify and Adium config when joining corp network
to = "corpnet01",
fn = {hs.fnutils.partial(reconfigSpotifyProxy, true),
hs.fnutils.partial(reconfigAdiumProxy, true),
}
},
{ -- Disable proxy in Spotify and Adium config when leaving corp network
from = "corpnet01",
fn = {hs.fnutils.partial(reconfigSpotifyProxy, false),
hs.fnutils.partial(reconfigAdiumProxy, false),
}
},
}
},
start = true,
}
)
-- The FadeLogo spoon simply shows an animation of the Hammerspoon logo to signal the end of the config load.
Install:andUse("FadeLogo",
{
config = {
default_run = 1.0,
},
start = false
}
)
-- If you don’t want to use FadeLogo, you can have a regular notification.
-- hs.notify.show("Welcome to Hammerspoon", "Have fun!", "")