-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch_modes.json.rb
357 lines (244 loc) · 16.2 KB
/
launch_modes.json.rb
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
#!/usr/bin/env ruby
# You can generate json by executing the following command on Terminal.
#
# $ ruby ./personal_christopherdwhite.json.rb > output/assets/complex_modifications/launch_modes.json
#
# # Parameters
PARAMETERS = {
:simultaneous_threshold_milliseconds => 500,
}.freeze
# # Imports
require 'json'
require_relative 'lib/karabiner.rb'
# # Functions
# ## main Function
#
# Defines the Karabiner complex modifications
#
def main
data = {
'title' => 'Launch Modes',
# ### Rules
'rules' => [
# #### Ⓩ Action Mode
{
'description' => 'Action Mode',
'manipulators' => [
# ##### Bartender
# Bartender: Toggle Bartender Bar Ⓑ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'b', %w[], false, [{ 'key_code' => 'f1', 'modifiers' => %w[control option] }]),
# Bartender: Maximize Menu Bar Items ⇧ Ⓑ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'b', %w[shift], false, [{ 'key_code' => 'f2', 'modifiers' => %w[control option] }]),
# Bartender: Show All Menu Bar Items ⌘ Ⓑ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'b', %w[command], false, [{ 'key_code' => 'f3', 'modifiers' => %w[control option] }]),
# Bartender: Search Menu Bar Items ⌥ Ⓑ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'b', %w[option], false, [{ 'key_code' => 'f4', 'modifiers' => %w[control option] }]),
# Bartender: Keyboard Select Menu Bar Items ^ Ⓑ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'b', %w[control], false, [{ 'key_code' => 'f5', 'modifiers' => %w[control option] }]),
# ##### Moom
# Moom: Center Window ⓪ [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', '0', %w[], [{ 'shell_command' => "osascript -e 'tell application\"Moom\"' -e 'center frontmost window geometrically' -e 'end tell'" }]),
# Moom: Zoom Window (-) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'hyphen', %w[], [{ 'key_code' => 'f6', 'modifiers' => %w[control option] }]),
# Moom: Zoom Window with Margin (=) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'equal_sign', %w[], [{ 'key_code' => 'f7', 'modifiers' => %w[control option] }]),
# Moom: Window to Left Half ([) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'open_bracket', %w[], false, [{ 'key_code' => 'f8', 'modifiers' => %w[control option] }]),
# Moom: Window to Right Half (]) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'close_bracket', %w[], false, [{ 'key_code' => 'f9', 'modifiers' => %w[control option] }]),
# Moom: Window to Left Third ⇧ ({) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'open_bracket', %w[shift], false, [{ 'key_code' => 'f10', 'modifiers' => %w[control option] }]),
# Moom: Window to Center Third ⇧ (|) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'backslash', %w[shift], [{ 'key_code' => 'f11', 'modifiers' => %w[control option] }]),
# Moom: Window to Right Third ⇧ (}) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'close_bracket', %w[shift], false, [{ 'key_code' => 'f12', 'modifiers' => %w[control option] }]),
# Moom: Window to Left Two Thirds ⇧ (<) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'comma', %w[shift], false, [{ 'key_code' => 'f13', 'modifiers' => %w[control option] }]),
# Moom: Window to Right Two Thirds ⇧ (>) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'period', %w[shift], false, [{ 'key_code' => 'f14', 'modifiers' => %w[control option] }]),
# Moom: Keyboard Control (;) [ Simulate Key ]
generate_launch_mode_rule('launch_mode', 'z', 'semicolon', %w[], [{ 'key_code' => 'f15', 'modifiers' => %w[control option] }]),
# Open URLs Ⓤ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('action_mode', 'z', 'u', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"4B75D6B9-61F0-4F93-AB7F-7CC998E81E51\"'" }]),
# Toggle Global Shortcuts with ShortStop Ⓧ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', 'x', %w[], [{ 'key_code' => 'f16', 'modifiers' => %w[control option shift] }]),
# ##### Typetto
# Typetto → ciPhone ① [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', '1', %w[], [{ 'key_code' => 'f17', 'modifiers' => %w[control option shift] }]),
# Typetto → ciPad ② [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', '2', %w[], [{ 'key_code' => 'f18', 'modifiers' => %w[control option shift] }]),
# Typetto → ciPhoneDev ③ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', '3', %w[], [{ 'key_code' => 'f19', 'modifiers' => %w[control option shift] }]),
# Typetto → ciPadDev ④ [ Simulate Key ]
generate_launch_mode_rule('action_mode', 'z', '4', %w[], [{ 'key_code' => 'f20', 'modifiers' => %w[control option shift] }]),
].flatten,
},
# #### Ⓐ Alfred Mode
{
'description' => 'Alfred Mode',
'manipulators' => [
# Alfred Maestro Ⓚ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'k', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"doMacro\" in workflow \"iansinnott.keyboardmaestro\"'" }]),
# AppScripts Ⓢ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 's', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"scripts\" in workflow \"net.deanishe.alfred-appscripts\"'" }]),
# Fantastical Ⓕ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'f', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"fantastical\" in workflow \"com.robertboehnke.alfred.fantastical\"'" }]),
# Menu Bar Search Ⓜ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'm', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"searchMenuBar\" in workflow \"com.tedwise.menubarsearch\"'" }]),
# Search Safari and Chrome Tabs Ⓦ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'w', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"searchTabs\" in workflow \"com.clintonstrong.SearchTabs\"'" }]),
# Searchio! → Bing Ⓑ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'b', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"bing\" in workflow \"net.deanishe.alfred-searchio\"'" }]),
# SnippetsLab Ⓛ [ Workflow ]
generate_launch_mode_rule('alfred_mode', 'a', 'l', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"searchSnippetsLab\" in workflow \"com.renfei.SnippetsLab.AlfredWorkflow\"'" }]),
].flatten,
},
# #### Ⓑ Bear Mode
{
'description' => 'Bear Mode',
'manipulators' => [
# Alfred `bear` ( Space ) `bear` [ Alfred Argument ]
generate_launch_mode_rule('bear_mode', 'b', 'spacebar', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to search \"Bear \"'" }]),
# Bear → Create New Bear Note Ⓒ [ Workflow ]
generate_launch_mode_rule('bear_mode', 'b', 'c', %w[], false, [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"newBearNote\" in workflow \"com.chrisbro.bear\"'" }]),
# Bear → Search Bear Notes Ⓢ [ Workflow ]
generate_launch_mode_rule('bear_mode', 'b', 's', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"searchBear\" in workflow \"com.chrisbro.bear\"'" }]),
# Bear → Search Bear Notes by Tag Ⓣ [ Workflow ]
generate_launch_mode_rule('bear_mode', 'b', 't', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Alfred 3\" to run trigger \"searchBearTag\" in workflow \"com.chrisbro.bear\"'" }]),
# New Bear Note ⌥ Ⓒ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('bear_mode', 'b', 'c', %w[option], false, [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"2E864E28-4288-4FB4-927D-61546A2E8805\"'" }]),
# New Bear Note in External Window ⌘ Ⓒ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('bear_mode', 'b', 'c', %w[command], false, [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"BF7F09AC-36B9-4A04-A594-79383A25FC0D\"'" }]),
# New Untagged Bear Note ^ Ⓒ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('bear_mode', 'b', 'c', %w[control], false, [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"CA6F631E-5440-4DCF-8228-76523FD9E966\"'" }]),
].flatten,
},
# #### Capture Mode
# #### Code Mode
# KM: Paste as Comments
# TextExpander: Swift from Clipboard
# TextExpander: Swift Code Fence
# #### Connect Mode
# #### DEVONthink Mode
# #### Markdown Code Mode
# #### Ⓟ Palettes Mode
{
'description' => 'Palettes Mode',
'manipulators' => [
# Toggle 1Password Mini ① [ Keyboard Maestro Macro ]
generate_launch_mode_rule('palettes_mode', 'p', '1', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"A849F0C3-2743-4023-A1D3-12CC4FCD106B\"'" }]),
# Toggle Copied Window Ⓒ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('palettes_mode', 'p', 'c', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"185780B3-6875-453F-8D0F-D925E2E03FF0\"'" }]),
# Toggle Dropzone Ⓓ [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'd', %w[], [{ 'key_code' => 'f3', 'modifiers' => %w[control option shift] }]),
# Toggle Fantastical Mini Window Ⓕ [ URL ]
generate_launch_mode_rule('palettes_mode', 'p', 'f', %w[], [{ 'shell_command' => "open x-fantastical2://show/mini" }]),
# Toggle HoudahSpot Search Bar Ⓗ [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'h', %w[], [{ 'key_code' => 'f5', 'modifiers' => %w[control option shift] }]),
# Toggle Keyboard Maestro Global Macro Palette Ⓚ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('palette_mode', 'p', 'k', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"C11F2723-618F-4CA6-B829-1D2C86207C65\"'" }]),
# Toggle SnippetsLab Assistant Ⓛ [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'l', %w[], [{ 'key_code' => 'f4', 'modifiers' => %w[control option shift] }]),
# Toggle TeaCode Quick Browser Ⓠ [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'q', %w[], [{ 'key_code' => 'f1', 'modifiers' => %w[control option shift] }]),
# Toggle TextExpander Inline Search [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'x', %w[], [{ 'key_code' => 'f2', 'modifiers' => %w[control option shift] }]),
# Toggle Things Quick Entry ⌥ Ⓣ [ AppleScript ]
generate_launch_mode_rule('palettes_mode', 'p', 't', %w[option], false, [{ 'shell_command' => "osascript -e 'tell application \"Things3\"' -e 'show quick entry panel' -e 'end tell'" }]),
# Toggle Things Quick Entry with Autofill Ⓣ [ AppleScript ]
generate_launch_mode_rule('palettes_mode', 'p', 't', %w[], false, [{ 'shell_command' => "osascript -e 'tell application \"Things3\"' -e 'show quick entry panel with autofill yes' -e 'end tell'" }]),
# Toggle Workspaces Browser Ⓦ [ Simulate Key ]
generate_launch_mode_rule('palettes_mode', 'p', 'w', %w[], [{ 'key_code' => 'f8', 'modifiers' => %w[control option shift] }]),
# Toggle Yoink Ⓨ [ Simulate Key ]
generate_launch_mode_rule('palette_mode', 'p', 'y', %w[], [{ 'key_code' => 'f10', 'modifiers' => %w[control option shift] }]),
].flatten,
},
# #### Productivity Mode
# #### Reference Mode (KeyCue)
# #### 🆆 Window Mode
{
'description' => 'Window Mode Mode',
'manipulators' => [
# Toggle Hyper Overlay Ⓣ [ Simulate Key ]
generate_launch_mode_rule('window_mode', 'w', 't', %w[], [{ 'key_code' => 'f6', 'modifiers' => %w[control option shift] }]),
# Toggle Finder Visor Ⓕ [ Keyboard Maestro Macro ]
generate_launch_mode_rule('window_mode', 'w', 'f', %w[], [{ 'shell_command' => "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"AB8CC6A1-E0D0-4D23-B36E-36823030FDDE\"'" }]),
# Open Code Window Ⓒ [ Simulate Key ]
generate_launch_mode_rule('window_mode', 'w', 'c', %w[], [{ 'key_code' => 'f7', 'modifiers' => %w[control option shift] }]),
# Toggle Numi Ⓝ [ Simulate Key ]
generate_launch_mode_rule('window_mode', 'w', 'n', %w[], [{ 'key_code' => 'f9', 'modifiers' => %w[control option shift] }]),
].flatten,
},
],
}
puts JSON.pretty_generate(data)
end
# ## generate_launch_mode
#
# Generates the necessary JSON required to define an action triggered in a launch mode.
# The first three paremeters specify the conditions required for the action to be launched, a trigger key that should be the same for all actions within a particular mode, a secondary key used to specify the action and optional modifiers that set required modifiers for an action.
# The optional_modifiers boolean designates whether 'any' optional modifiers are allowed for an action or whether none are. Generally speaking you want to allow for any optionals except for when you're defining multiple actions with with the same trigger key and from key but different modifiers. 'Any' optional modifiers is greedy so other actions with required modifiers will never be executed.
# The key code and and modifier combinations should be unique for each mode and its respective trigger key.
#
# Parameters:
# - `mode`: string Required ID string for the mode.
# - `trigger_key`: string Required Key used to enter launch mode.
# - `from_key_code`: string Required Key used to execute action when pressed
# - `mandatory_modifiers`: array Requred One or more modifier keys. Leave empty for none
# - `any_optional` boolean Optional Allow 'any' optional modifiers when true, none when false. Defaults true.
# - `to`: string Required Action to be performed
#
# Return: `data` array Generated JSON object
def generate_launch_mode_rule(mode, trigger_key, from_key_code, mandatory_modifiers, any_optional = true, to)
data = []
# Specify `'any'` optional monifiers unless explicitly set to false.
if any_optional == true
optional_modifiers = ['any']
else
optional_modifiers = []
end
# ### Generate Actionoptional_modifiers
h = {
'type' => 'basic',
'from' => {
'key_code' => from_key_code,
'modifiers' => Karabiner.from_modifiers(mandatory_modifiers, optional_modifiers),
},
'to' => to,
'conditions' => [Karabiner.variable_if(mode, 1)],
}
data << h
# ### Generate Condition
h = {
'type' => 'basic',
'from' => {
'simultaneous' => [
{ 'key_code' => trigger_key },
{ 'key_code' => from_key_code },
],
'simultaneous_options' => {
'key_down_order' => 'strict',
'key_up_order' => 'strict_inverse',
'to_after_key_up' => [
Karabiner.set_variable(mode, 0),
],
},
'modifiers' => Karabiner.from_modifiers(mandatory_modifiers, optional_modifiers),
},
'to' => [
Karabiner.set_variable(mode, 1),
].concat(to),
'parameters' => {
'basic.simultaneous_threshold_milliseconds' => PARAMETERS[:simultaneous_threshold_milliseconds],
},
}
data << h
data
end
# # Execute
main
# # Consumed Function Keys
#
# This is the primary place I'm defining global funtion keys shotcuts like ^⌥⌘ F1 so it's easy to make sure you don't have two actions assigned to the same hotkey. However, there are rare events where I define them elsewhere and I've listed them here for reference.
#
# - ^⌥⇧⌘ F12: Expand with TeaCode.