-
Notifications
You must be signed in to change notification settings - Fork 13
/
init.lua
330 lines (298 loc) · 9.02 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
hs.loadSpoon('Hyper')
hs.loadSpoon('Headspace'):start()
hs.loadSpoon('Teamz'):start()
hs.loadSpoon('HyperModal')
IsDocked = function()
return hs.fnutils.some(hs.usb.attachedDevices(), function(device)
return device.productName == "CalDigit Thunderbolt 3 Audio"
end)
end
Config = {}
Config.applications = require('configApplications')
Hyper = spoon.Hyper
Hyper:bindHotKeys({hyperKey = {{}, 'F19'}})
hs.fnutils.each(Config.applications, function(appConfig)
if appConfig.hyperKey then
Hyper:bind({}, appConfig.hyperKey, function() hs.application.launchOrFocusByBundleID(appConfig.bundleID) end)
end
if appConfig.localBindings then
hs.fnutils.each(appConfig.localBindings, function(key)
Hyper:bindPassThrough(key, appConfig.bundleID)
end)
end
end)
-- provide the ability to override config per computer
if (hs.fs.displayName('./localConfig.lua')) then
require('localConfig')
end
-- https://github.com/dmitriiminaev/Hammerspoon-HyperModal/blob/master/.hammerspoon/yabai.lua
local yabai = function(args, completion)
local yabai_output = ""
local yabai_error = ""
-- Runs in background very fast
local yabai_task = hs.task.new("/run/current-system/sw/bin/yabai", function(err, stdout, stderr)
print()
end, function(task, stdout, stderr)
-- print("stdout:"..stdout, "stderr:"..stderr)
if stdout ~= nil then
yabai_output = yabai_output .. stdout
end
if stderr ~= nil then
yabai_error = yabai_error .. stderr
end
return true
end, args)
if type(completion) == "function" then
yabai_task:setCallback(function()
completion(yabai_output, yabai_error/run/current-system/sw/bin/yabai)
end)
end
yabai_task:start()
end
HyperModal = spoon.HyperModal
HyperModal
:start()
:bind('', "1", function()
yabai({"-m", "window", "--swap", "first"})
HyperModal:exit()
end)
:bind('', "z", function()
yabai({"-m", "window", "--toggle", "zoom-parent"})
HyperModal:exit()
end)
:bind('', "v", function()
yabai({"-m", "space", "--mirror", "y-axis"})
HyperModal:exit()
end)
:bind('', "x", function()
yabai({"-m", "window", "--toggle", "split"})
HyperModal:exit()
end)
:bind('', "space", function()
yabai({"-m", "window", "--toggle", "zoom-fullscreen"})
HyperModal:exit()
end)
:bind('', "h", function()
yabai({"-m", "window", "--swap", "west"})
HyperModal:exit()
end)
:bind('', "j", function()
yabai({"-m", "window", "--swap", "south"})
HyperModal:exit()
end)
:bind('', "k", function()
yabai({"-m", "window", "--swap", "north"})
HyperModal:exit()
end)
:bind('', "l", function()
yabai({"-m", "window", "--swap", "east"})
HyperModal:exit()
end)
:bind({"alt"}, "h", function()
yabai({"-m", "window", "--warp", "west"})
HyperModal:exit()
end)
:bind({"alt"}, "j", function()
yabai({"-m", "window", "--warp", "south"})
HyperModal:exit()
end)
:bind({"alt"}, "k", function()
yabai({"-m", "window", "--warp", "north"})
HyperModal:exit()
end)
:bind({"alt"}, "l", function()
yabai({"-m", "window", "--warp", "east"})
HyperModal:exit()
end)
:bind({'shift'}, "l", function()
yabai({"-m", "window", "--display", "east"})
HyperModal:exit()
end)
:bind({'shift'}, "h", function()
yabai({"-m", "window", "--display", "west"})
HyperModal:exit()
end)
:bind("", "s", function()
yabai({"-m", "window", "--stack", "mouse"})
HyperModal:exit()
end)
:bind('', "r", function()
yabai({"-m", "space", "--balance"})
HyperModal:exit()
end)
:bind({"shift"}, "b", function()
yabai({"-m", "space", "--layout", "stack"})
HyperModal:exit()
end)
:bind("", "b", function()
yabai({"-m", "space", "--layout", "bsp"})
HyperModal:exit()
end)
:bind('', ';', function()
hs.urlevent.openURL("raycast://extensions/raycast/system/toggle-system-appearance")
HyperModal:exit()
end)
Hyper:bind({}, 'm', function() HyperModal:toggle() end)
local brave = require('brave')
brave.start(Config)
-- Random bindings
Hyper:bind({}, 'r', nil, function()
hs.application.launchOrFocusByBundleID('org.hammerspoon.Hammerspoon')
end)
Hyper:bind({'shift'}, 'r', nil, function() hs.reload() end)
local chooseFromGroup = function(choice)
local name = hs.application.nameForBundleID(choice.bundleID)
hs.notify.new(nil)
:title("Switching ✦-" .. choice.key .. " to " .. name)
:contentImage(hs.image.imageFromAppBundle(choice.bundleID))
:send()
hs.settings.set("group." .. choice.tag, choice.bundleID)
hs.application.launchOrFocusByBundleID(choice.bundleID)
end
local hyperGroup = function(key, tag)
Hyper:bind({}, key, nil, function()
hs.application.launchOrFocusByBundleID(hs.settings.get("group." .. tag))
end)
Hyper:bind({'option'}, key, nil, function()
local group =
hs.fnutils.filter(Config.applications, function(app)
return app.tags and
hs.fnutils.contains(app.tags, tag) and
app.bundleID ~= hs.settings.get("group." .. tag)
end)
local choices = {}
hs.fnutils.each(group, function(app)
table.insert(choices, {
text = hs.application.nameForBundleID(app.bundleID),
image = hs.image.imageFromAppBundle(app.bundleID),
bundleID = app.bundleID,
key = key,
tag = tag
})
end)
if #choices == 1 then
chooseFromGroup(choices[1])
else
hs.chooser.new(chooseFromGroup)
:placeholderText("Choose an application for hyper+" .. key .. ":")
:choices(choices)
:show()
end
end)
end
hyperGroup('q', 'personal')
hyperGroup('k', 'browsers')
hyperGroup('i', 'chat')
-- Jump to google hangout or zoom
Z_count = 0
Hyper:bind({}, 'z', nil, function()
Z_count = Z_count + 1
hs.timer.doAfter(0.2, function()
Z_count = 0
end)
if Z_count == 2 then
spoon.ElgatoKey:toggle()
else
-- start a timer
-- if not pressed again then
if hs.application.find('us.zoom.xos') then
hs.application.launchOrFocusByBundleID('us.zoom.xos')
elseif hs.application.find('com.microsoft.teams2') then
hs.application.launchOrFocusByBundleID('com.microsoft.teams2')
local call = hs.settings.get("call")
call:focus()
else
brave.jump("meet.google.com|hangouts.google.com.call")
end
end
end)
-- Jump to figma
Hyper:bind({}, 'v', nil, function()
if hs.application.find('com.figma.Desktop') then
hs.application.launchOrFocusByBundleID('com.figma.Desktop')
elseif hs.application.find('com.electron.realtimeboard') then
hs.application.launchOrFocusByBundleID('com.electron.realtimeboard')
elseif hs.application.find('com.adobe.LightroomClassicCC7') then
hs.application.launchOrFocusByBundleID('com.adobe.LightroomClassicCC7')
else
brave.jump("lucidchart.com|figma.com")
end
end)
Hyper:bind({}, 'p', nil, function()
local _success, projects, _output = hs.osascript.javascript([[
(function() {
var Things = Application("Things");
var divider = /## Resources/;
Things.launch();
let getUrls = function(proj) {
if (proj.notes() && proj.notes().match(divider)) {
return proj.notes()
.split(divider)[1]
.replace(divider, "")
.split("\n")
.map(str => str.replace(/^- /, ""))
.filter(s => s != "")
}
else {
return false;
}
}
let projects =
Things
.projects()
.filter(t => t.status() == "open")
.map(function(proj) {
return {
text: proj.name(),
subText: proj.area().name(),
urls: getUrls(proj),
id: proj.id()
}
})
.filter(function(proj) {
return proj.urls
});
return projects;
})();
]])
hs.chooser.new(function(choice)
hs.fnutils.each(choice.urls, hs.urlevent.openURL)
hs.urlevent.openURL("things:///show?id=" .. choice.id)
end)
:placeholderText("Choose a project…")
:choices(projects)
:show()
end)
require('browserSnip')
-- sync tags to OSX
-- Currently unused, because of permissions
Config.appsync = function()
hs.fnutils.map(Config.applications, function(a)
if a["tags"] and a["bundleID"] then
local app_path = hs.application.pathForBundleID(a["bundleID"]) -- may not be installed!
if app_path then
if not a["bundleID"]:find("apple") then
print("attempting " .. app_path)
print(hs.inspect(a["tags"]))
hs.fs.tagsSet(app_path, a["tags"])
end
end
end
end)
end
-- change audio settings based on output
hs.audiodevice.watcher.setCallback(function(event)
if event == "dOut" then
local name = hs.audiodevice.defaultOutputDevice():name()
if name == "WH-1000XM4" then
hs.shortcuts.run("XM4")
end
if name == "MacBook Pro Speakers" then
hs.shortcuts.run("Macbook Pro Speakers")
end
end
end)
hs.audiodevice.watcher.start()
Hyper:bind({}, 'w', nil, function()
hs.window.focusedWindow():application():selectMenuItem({"Edit", "Start Dictation"})
end)