-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
509 lines (438 loc) · 14.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
-- Hammerspoon window management shortcuts
-- ,------------------------------------------. ,----------------------------+------+--------.
-- ____, 1/6 , 2/6 , 3/6 , 1/4, 2/4, 3/4, 4/4, 4/6, 5/6, 6/6, ____ ,
-- |--------+-----+------+------+------+------| |------+------+------+-------+------+--------|
-- ____ , 1/3 , 2/3 , 3/3, fullscr,Layout, ____, Focu_l, Focu_u, Focu_r,____ , ____
-- |--------+-----+------+------+------+------+------+------.,------+------+------+------+------+-------+------+--------|
-- ____ , ____, ____, ____, ____, ____, ____, ____, ____, ____,LScn , Rscn Focu_d, ____, ____, ____,
-- `---------------------+------+------+------+------+------||------+------+------+------+------+-----------------------'
-- _____, _____, _____, _____, _____, _____, _____, _____, _____, ____
-- `----------------------------------'`----------------------------------'
-- Screen is Dell 49 inch. Running with displayport and hdmi cable as two external monitors
hs.window.animationDuration = 0
leftScreen = hs.screen.primaryScreen(0x600003f98880)
rightScreen = leftScreen:toEast()
-- Set shortcuts to move windows between displays Hyper+N for leftScreen and hyper+M for rightScreen
function moveWindowToDisplay(d)
return function()
local displays = hs.screen.allScreens()
local win = hs.window.focusedWindow()
win:moveToScreen(displays[d], false, true)
end
end
local win = hs.window.focusedWindow()
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "N", moveWindowToDisplay(1))
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "M", moveWindowToDisplay(2))
-- Set positions that can be used in grid and layout
positions = {
maximized = hs.layout.maximized,
centered = {x=0.15, y=0.15, w=0.7, h=0.7},
fullscreen = {x=0, y=0, w=2, h=1},
leftthird = {x=0, y=0, w=0.333, h=1},
middlethird = {x=0.3334, y=0, w=0.3334, h=1},
rightthird = {x=0.666, y=0, w=0.3334, h=1},
betweenscreens = {x=0.666, y=0, w=0.666, h=1},
twothirdsleft = {x=0, y=0, w=0.666, h=1},
twothidsright= {x=0.3334, y=0, w=0.666, h=1},
left50 = hs.layout.left50,
left75 = hs.layout.left75,
left66 = {x=0, y=0, w=0.666, h=1},
right50 = hs.layout.right50,
right75 = hs.layout.right75,
right66 = {x=0.3334, y=0, w=0.666, h=1},
upper50 = {x=0, y=0, w=1, h=0.5},
upper50Left50 = {x=0, y=0, w=0.5, h=0.5},
upper50Right50 = {x=0.5, y=0, w=0.5, h=0.5},
lower50 = {x=0, y=0.5, w=1, h=0.5},
lower50Left50 = {x=0, y=0.5, w=0.5, h=0.5},
lower50Right50 = {x=0.5, y=0.5, w=0.5, h=0.5}
}
function bindKey(key, fn)
hs.hotkey.bind({"cmd", "ctrl","alt"}, key, fn)
end
grid = {
--{key="q", units={positions.leftthird, positions.left50, positions.left66, }},
--{key="w", units={positions.middlethird, positions.left66, positions.right66}},
--{key="e", units={positions.rightthird, positions.right50, positions.right66,}},
--{key="f", units={positions.maximized, positions.right75, positions.left75}},
--{key="h", units={positions.twothirdsleft}},
--{key="j", units={positions.betweenscreens}},
--{key="k", units={positions.twothidsright}},
--{key="x", units={positions.right66}},
--{key="z", units={positions.left66}},
-- {key="r", units={positions.left50, positions.lower50Left50, positions.upper50Left50, positions.upper50, positions.lower50}}, -- virker IKKE på sekundære skærm?
-- {key="t", units={positions.right50, positions.lower50Right50, positions.upper50Right50, positions.upper50, positions.lower50}}, -- virker IKKE på sekundære skærm?
}
hs.fnutils.each(grid, function(entry)
bindKey(entry.key, function()
local units = entry.units
-- Jeg kan ikke få grids til at virke med begge skærme
local screen = hs.screen.mainScreen()
local window = hs.window.focusedWindow()
local windowGeo = window:frame()
local index = 0
hs.fnutils.find(units, function(unit)
index = index + 1
local geo = hs.geometry.new(unit):fromUnitRect(screen:frame()):floor()
return windowGeo:equals(geo)
end)
if index == #units then index = 0 end
window:moveToUnit(units[index + 1])
end)
end)
--Ved at bruge demme kode istedet for grid kan man placere direkte på ve og hø skærm uden at bruge genvejene til at skifte skærm først: hyper n og hyper m
----------
--to trejdedel venstre
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "a", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w - (max.w *0.333)
f.h = max.h
win:setFrame(f)
end)
----------
--to trejdedel midt
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "s", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w *0.666)
f.y = max.y
f.w = max.w - (max.w *0.333)
f.h = max.h
win:setFrame(f)
end)
----------
--to trejdedel højre
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "d", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x + (max.w *0.333)
f.y = max.y
f.w = max.w - (max.w *0.333)
f.h = max.h
win:setFrame(f)
end)
----------
--en trejdedel venstre - leftScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "q", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
--en trejdedel midt - leftScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "w", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w *0.333)
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
--en trejdedel højre - leftScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "e", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w *0.666)
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
----------
----------
--en trejdedel venstre - rightScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "i", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
--en trejdedel midt - rightScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "o", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x + (max.w *0.333)
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
--en trejdedel højre - rightScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "p", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x + (max.w *0.666)
f.y = max.y
f.w = max.w /3
f.h = max.h
win:setFrame(f)
end)
----------
----------
--en ve halvdel - leftScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w /2
f.h = max.h
win:setFrame(f)
end)
----------
--en ve halvdel - leftScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "t", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w *0.5)
f.y = max.y
f.w = max.w /2
f.h = max.h
win:setFrame(f)
end)
----------
--en ve halvdel - rightScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "y", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w /2
f.h = max.h
win:setFrame(f)
end)
----------
--en hø halvdel - rightScreen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "u", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = rightScreen
local max = screen:frame()
f.x = max.x + (max.w *0.5)
f.y = max.y
f.w = max.w /2
f.h = max.h
win:setFrame(f)
end)----------
--maximized - left screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "g", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
----------
--maximized - right screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "h", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w * 1)
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
--maximized - BOTH screens
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "f", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w + (max.w)
f.h = max.h
win:setFrame(f)
end)
--midt - to fjeredele
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "m", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = leftScreen
local max = screen:frame()
f.x = max.x + (max.w *0.5)
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
----------
----------
--Åbne Chrome vinduer-----------------------------------------------------
--hs.hotkey.bind({"cmd", "alt", "ctrl"}, 'v', function()
-- hs.application.open("Google Chrome", wait, waitForFirstWindow)
--hs.eventtap.keyStroke({"cmd","alt", "ctrl"}, "N") --placerering venstreskærm
--hs.eventtap.keyStroke({"cmd","alt", "ctrl"}, "q") --placerering leftthird
--hs.eventtap.keyStroke({"cmd"}, "n")
--hs.eventtap.keyStroke({"cmd","alt", "ctrl"}, "e") --placerering rightthird
--hs.eventtap.keyStroke({"cmd","alt", "ctrl"}, "M") --placerering højreskærm
--end)
--layouts. Snaps all windows in place with a hotkey.
local bLayout = {
--rightScreen
--fullscreen
{"Obsidian", nil, rightScreen, hs.layout.fullscreen, nil, nil},
--left50
{"Sublime Text", nil, rightScreen, hs.layout.left50, nil, nil},
{"Microsoft Word", nil, rightScreen, hs.layout.left50, nil, nil},
--right50
{"Books", nil, rightScreen, positions.right50, nil, nil},
--leftthird
{"Spotify", nil, rightScreen, hs.layout.leftthird, nil, nil},
--middlethird
{"iterm", nil, rightScreen, hs.layout.middlethird, nil, nil},
--rightthird
{"Facebook Messenger", nil, rightScreen, positions.rightthird, nil, nil},
--leftScreen
--left50
{"Google Chrome", nil, leftScreen, hs.layout.left50, nil, nil},
{"Calibre", nil, leftScreen, hs.layout.left50, nil, nil},
{"Zotero", nil, leftScreen, positions.left50, nil, nil},
{"Signal", nil, leftScreen, positions.left50, nil, nil},
--right50
{"Skim", nil, leftScreen, positions.right50, nil, nil},
{"Google Chrome", nil, leftScreen, hs.layout.right50, nil, nil},
{"Outlook", nil, leftScreen, positions.right50, nil, nil},
{"Discord", nil, leftScreen, positions.right50, nil, nil},
--leftthird
--middlethird
--rightthird
}
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "b", function()
hs.layout.apply(gLayout)
end)
--Focus window. Changes the focusedWindow with shortcuts
local hyper2 = {"cmd", "alt", "ctrl", "shift"}
hs.hotkey.bind(hyper2, 'o', function()
if hs.window.focusedWindow() then
hs.window.focusedWindow():focusWindowNorth()
-- Center mouse on Window after focus or switch occurs
currentWindow = hs.window.focusedWindow()
currentFrame = currentWindow:frame()
cfx = currentFrame.x + (currentFrame.w / 2)
cfy = currentFrame.y + (currentFrame.h / 2)
cfp = hs.geometry.point(cfx, cfy)
hs.mouse.setAbsolutePosition(cfp)
else
hs.alert.show("No active window")
end
end)
hs.hotkey.bind(hyper2, 'e', function()
if hs.window.focusedWindow() then
hs.window.focusedWindow():focusWindowSouth()
-- Center mouse on Window after focus or switch occurs
currentWindow = hs.window.focusedWindow()
currentFrame = currentWindow:frame()
cfx = currentFrame.x + (currentFrame.w / 2)
cfy = currentFrame.y + (currentFrame.h / 2)
cfp = hs.geometry.point(cfx, cfy)
hs.mouse.setAbsolutePosition(cfp)
else
hs.alert.show("No active window")
end
end)
hs.hotkey.bind(hyper2, 'i', function()
if hs.window.focusedWindow() then
hs.window.focusedWindow():focusWindowEast()
-- Center mouse on Window after focus or switch occurs
currentWindow = hs.window.focusedWindow()
currentFrame = currentWindow:frame()
cfx = currentFrame.x + (currentFrame.w / 2)
cfy = currentFrame.y + (currentFrame.h / 2)
cfp = hs.geometry.point(cfx, cfy)
hs.mouse.setAbsolutePosition(cfp)
else
hs.alert.show("No active window")
end
end)
hs.hotkey.bind(hyper2, 'a', function()
if hs.window.focusedWindow() then
hs.window.focusedWindow():focusWindowWest()
-- Center mouse on Window after focus or switch occurs
currentWindow = hs.window.focusedWindow()
currentFrame = currentWindow:frame()
cfx = currentFrame.x + (currentFrame.w / 2)
cfy = currentFrame.y + (currentFrame.h / 2)
cfp = hs.geometry.point(cfx, cfy)
hs.mouse.setAbsolutePosition(cfp)
else
hs.alert.show("No active window")
end
end)
hs.hotkey.bind(hyper2, "p", function()
hs.window.highlight.ui.overlayColor = {0.2,0.05,0,0.25}
hs.window.highlight.start()
end)
hs.hotkey.bind(hyper2, ",", function()
hs.window.highlight.toggleIsolate(v)
end)
------
------
------Defeat Paste blocking
------
------
hs.hotkey.bind({"cmd", "alt"}, "V", function() hs.eventtap.keyStrokes(hs.pasteboard.getContents()) end)
wifiwatcher = hs.wifi.watcher.new(function ()
net = hs.wifi.currentNetwork()
if net==nil then
hs.notify.show("You lost Wi-Fi connection","","","")
else
hs.notify.show("Connected to Wi-Fi network","",net,"")
end
end)
wifiwatcher:start()
-------------------
-----Reload config - automaticly reload config after saving this file
-------------------
hs.loadSpoon("ReloadConfiguration")
spoon.ReloadConfiguration:start()
hs.alert.show("Config loaded")
-------------------
-------------------
-------------------