forked from zzamboni/dot-hammerspoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
519 lines (469 loc) · 16.5 KB
/
init.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
-- DO NOT EDIT THIS FILE DIRECTLY
-- This is a file generated from a literate programing source file located at
-- https://github.com/zzamboni/dot-hammerspoon/blob/master/init.org.
-- You should make any changes there and regenerate it from Emacs org-mode using C-c C-v t
hs.logger.defaultLogLevel="info"
hyper = {"cmd","alt","ctrl"}
shift_hyper = {"cmd","alt","ctrl","shift"}
ctrl_cmd = {"cmd","ctrl"}
col = hs.drawing.color.x11
work_logo = hs.image.imageFromPath(hs.configdir .. "/files/work_logo_2x.png")
hs.loadSpoon("SpoonInstall")
spoon.SpoonInstall.repos.zzspoons = {
url = "https://github.com/zzamboni/zzSpoons",
desc = "zzamboni's spoon repository",
}
spoon.SpoonInstall.use_syncinstall = true
Install=spoon.SpoonInstall
-- Install:andUse("BetterTouchTool", { loglevel = 'debug' })
-- BTT = spoon.BetterTouchTool
function appID(app)
return hs.application.infoForBundlePath(app)['CFBundleIdentifier']
end
chromeBrowser = appID('/Applications/Google Chrome.app')
-- edgeBrowser = appID('/Applications/Microsoft Edge.app')
braveBrowser = appID('/Applications/Brave Browser.app')
DefaultBrowser = chromeBrowser
WorkBrowser = chromeBrowser
-- JiraApp = appID('~/Applications/Epichrome SSBs/Jira.app')
-- WikiApp = appID('~/Applications/Epichrome SSBs/Wiki.app')
-- CollabApp = WorkBrowser
-- SmcaApp = WorkBrowser
-- OpsGenieApp = WorkBrowser
-- TeamsApp = appID('/Applications/Microsoft Teams.app')
QuipApp = appID('/Applications/Quip.app')
Install:andUse("URLDispatcher",
{
config = {
url_patterns = {
{ "https://quip%-amazon%.com/", QuipApp }
-- { "https?://issue%.swisscom%.ch", JiraApp },
-- { "https?://issue%.swisscom%.com", JiraApp },
-- { "https?://jira%.swisscom%.com", JiraApp },
-- { "https?://wiki%.swisscom%.com", WikiApp },
-- { "https?://collab.*%.swisscom%.com", CollabApp },
-- { "https?://smca%.swisscom%.com", SmcaApp },
-- { "https?://app.*%.opsgenie%.com", OpsGenieApp },
-- { "msteams:", TeamsApp },
-- { "https?://.*%.swisscom%.ch", WorkBrowser },
-- { "https?://.*%.swisscom%.com", WorkBrowser },
-- { "https?://.*%.sharepoint%.com", WorkBrowser },
-- { "https?://.*%.office%.com", WorkBrowser },
-- { "https?://.*%.corproot%.net", WorkBrowser }
},
url_redir_decoders = {
-- This breaks some things
-- { "Fix macOS double-encoding weirdness",
-- "%%25(%x%x)", -- This is %xx encoded, the % gets converted to %25
-- "%%%1", true },
-- { "Office 365 safelinks check",
-- "https://eur03.safelinks.protection.outlook.com/(.*)\\?url=(.-)&.*",
-- "%2" },
-- { "MS Teams URLs",
-- "(https://teams.microsoft.com.*)", "msteams:%1", true },
{ "Fix broken Preview anchor URLs",
"%%23", "#", false, "Preview" },
},
default_handler = DefaultBrowser
},
start = true,
-- loglevel = 'debug'
}
)
Install:andUse("WindowHalfsAndThirds",
{
config = {
use_frame_correctness = true
},
hotkeys = 'default',
-- loglevel = 'debug'
}
)
myGrid = { w = 6, h = 4 }
Install:andUse("WindowGrid",
{
config = { gridGeometries =
{ { myGrid.w .."x" .. myGrid.h } } },
hotkeys = {show_grid = {hyper, "g"}},
start = true
}
)
Install:andUse("WindowScreenLeftAndRight",
{
config = {
animationDuration = 0
},
hotkeys = 'default',
-- loglevel = 'debug'
}
)
Install:andUse("ToggleScreenRotation",
{
hotkeys = { first = {hyper, "f15"} }
}
)
Install:andUse("UniversalArchive",
{
config = {
evernote_archive_notebook = ".Archive",
archive_notifications = false,
outlook_archive_folder = "Archive ([email protected])"
},
hotkeys = { archive = { { "ctrl", "cmd" }, "a" } }
}
)
function chrome_item(n)
return { apptype = "chromeapp", itemname = n }
end
function OF_register_additional_apps(s)
s:registerApplication("Swisscom Collab", chrome_item("tab"))
s:registerApplication("Swisscom Wiki", chrome_item("wiki page"))
s:registerApplication("Swisscom Jira", chrome_item("issue"))
s:registerApplication("Brave Browser", chrome_item("page"))
end
Install:andUse("SendToOmniFocus",
{
disable = true,
config = {
quickentrydialog = false,
notifications = false
},
hotkeys = {
send_to_omnifocus = { hyper, "t" }
},
fn = OF_register_additional_apps,
}
)
org_capture_path = os.getenv("HOME").."/.hammerspoon/files/org-capture.lua"
script_file = io.open(org_capture_path, "w")
script_file:write([[local win = hs.window.frontmostWindow()
local o,s,t,r = hs.execute("~/.emacs.d/bin/org-capture", true)
if not s then
print("Error when running org-capture: "..o.."\n")
end
win:focus()
]])
script_file:close()
hs.hotkey.bindSpec({hyper, "t"},
function ()
hs.task.new("/bin/bash", nil, { "-l", "-c", "/usr/local/bin/hs "..org_capture_path }):start()
end
)
Install:andUse("EvernoteOpenAndTag",
{
disable = true,
hotkeys = {
open_note = { hyper, "o" },
["open_and_tag-+work"] = { hyper, "w" },
["open_and_tag-+personal"] = { hyper, "p" },
["tag-@zzdone"] = { hyper, "z" }
}
}
)
Install:andUse("TextClipboardHistory",
{
disable = true,
config = {
show_in_menubar = false,
},
hotkeys = {
toggle_clipboard = { { "cmd", "shift" }, "v" } },
start = true,
}
)
Install:andUse("Hammer",
{
repo = 'zzspoons',
config = { auto_reload_config = false },
hotkeys = {
config_reload = {hyper, "r"},
toggle_console = {hyper, "y"}
},
-- fn = BTT_restart_Hammerspoon,
start = true
}
)
Install:andUse("Caffeine", {
start = true,
hotkeys = {
toggle = { hyper, "1" }
},
-- fn = BTT_caffeine_widget,
})
Install:andUse("MenubarFlag",
{
config = {
colors = {
["U.S."] = { },
Spanish = {col.green, col.white, col.red},
["Latin American"] = {col.green, col.white, col.red},
German = {col.black, col.red, col.yellow},
}
},
start = true
}
)
Install:andUse("MouseCircle",
{
disable = true,
config = {
color = hs.drawing.color.x11.rebeccapurple
},
hotkeys = {
show = { hyper, "m" }
}
}
)
Install:andUse("ColorPicker",
{
disable = true,
hotkeys = {
show = { hyper, "z" }
},
config = {
show_in_menubar = false,
},
start = true,
}
)
Install:andUse("BrewInfo",
{
config = {
brew_info_style = {
textFont = "Inconsolata",
textSize = 14,
radius = 10 }
},
hotkeys = {
-- brew info
show_brew_info = {hyper, "b"},
open_brew_url = {shift_hyper, "b"},
-- brew cask info - not needed anymore, the above now do both
-- show_brew_cask_info = {shift_hyper, "c"},
-- open_brew_cask_url = {hyper, "c"},
}
}
)
Install:andUse("TimeMachineProgress",
{
start = true
}
)
Install:andUse("TurboBoost",
{
disable = true,
config = {
disable_on_start = true
},
hotkeys = {
toggle = { hyper, "0" }
},
start = true,
-- loglevel = 'debug'
}
)
Install:andUse("EjectMenu", {
config = {
eject_on_lid_close = false,
eject_on_sleep = false,
show_in_menubar = true,
notify = true,
},
hotkeys = { ejectAll = { hyper, "=" } },
start = true,
-- loglevel = 'debug'
})
Install:andUse("HeadphoneAutoPause",
{
start = true,
disable = true,
}
)
Install:andUse("Seal",
{
hotkeys = { show = { {"alt"}, "space" } },
fn = function(s)
s:loadPlugins({"apps", "calc", "safari_bookmarks",
"screencapture", "useractions"})
s.plugins.safari_bookmarks.always_open_with_safari = false
s.plugins.useractions.actions =
{
["Hammerspoon docs webpage"] = {
url = "http://hammerspoon.org/docs/",
icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
},
["Leave corpnet"] = {
fn = function()
spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
end,
icon = work_logo,
},
["Arrive in corpnet"] = {
fn = function()
spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
end,
icon = work_logo,
},
["Translate using Leo"] = {
url = "http://dict.leo.org/englisch-deutsch/${query}",
icon = 'favicon',
keyword = "leo",
}
}
s:refreshAllCommands()
end,
start = true,
}
)
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
-- 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
function reconfigAdiumProxy(proxy)
app = hs.application.find("Adium")
if app and app:isRunning() then
local script = string.format([[
tell application "Adium"
repeat with a in accounts
if (enabled of a) is true then
set proxy enabled of a to %s
end if
end repeat
go offline
go online
end tell
]], hs.inspect(proxy))
hs.osascript.applescript(script)
end
end
function stopApp(name)
app = hs.application.get(name)
if app and app:isRunning() then
app:kill()
end
end
function forceKillProcess(name)
hs.execute("pkill " .. name)
end
function startApp(name)
hs.application.open(name)
end
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 config when joining corp network
to = "corpnet01",
fn = {hs.fnutils.partial(reconfigSpotifyProxy, true),
hs.fnutils.partial(reconfigAdiumProxy, true),
hs.fnutils.partial(forceKillProcess, "Dropbox"),
hs.fnutils.partial(stopApp, "Evernote"),
}
},
{ -- Disable proxy config when leaving corp network
from = "corpnet01",
fn = {hs.fnutils.partial(reconfigSpotifyProxy, false),
hs.fnutils.partial(reconfigAdiumProxy, false),
hs.fnutils.partial(startApp, "Dropbox"),
}
},
}
},
start = true,
}
)
local wm=hs.webview.windowMasks
Install:andUse("PopupTranslateSelection",
{
disable = true,
config = {
popup_style = wm.utility|wm.HUD|wm.titled|
wm.closable|wm.resizable,
},
hotkeys = {
translate_to_en = { hyper, "e" },
translate_to_de = { hyper, "d" },
translate_to_es = { hyper, "s" },
translate_de_en = { shift_hyper, "e" },
translate_en_de = { shift_hyper, "d" },
}
}
)
Install:andUse("DeepLTranslate",
{
disable = true,
config = {
popup_style = wm.utility|wm.HUD|wm.titled|
wm.closable|wm.resizable,
},
hotkeys = {
translate = { hyper, "e" },
}
}
)
Install:andUse("Leanpub",
{
config = {
watch_books = {
-- api_key gets set in init-local.lua like this:
-- spoon.Leanpub.api_key = "my-api-key"
{ slug = "learning-hammerspoon" },
{ slug = "learning-cfengine" },
{ slug = "emacs-org-leanpub" },
{ slug = "be-safe-on-the-internet" },
{ slug = "lit-config" },
{ slug = "zztestbook" },
{ slug = "cisspexampreparationguide" },
},
books_sync_to_dropbox = true,
},
start = true,
disable = true
})
Install:andUse("KSheet", {
hotkeys = {
toggle = { hyper, "/" }
}
})
local localfile = hs.configdir .. "/init-local.lua"
if hs.fs.attributes(localfile) then
dofile(localfile)
end
Install:andUse("FadeLogo",
{
config = {
default_run = 1.0,
},
start = true
}
)
-- hs.notify.show("Welcome to Hammerspoon", "Have fun!", "")