-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
107 lines (87 loc) · 4.28 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
-- Hammerspoon config
hs.window.animationDuration = 0
units = {
left75 = { x = 0.00, y = 0.00, w = 0.75, h = 1.00 },
right25 = { x = 0.75, y = 0.00, w = 0.25, h = 1.00 },
right50 = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 },
left50 = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 },
top50 = { x = 0.00, y = 0.00, w = 1.00, h = 0.50 },
bot50 = { x = 0.00, y = 0.50, w = 1.00, h = 0.50 },
topleft = { x = 0.00, y = 0.00, w = 0.50, h = 0.50 },
topright = { x = 0.50, y = 0.00, w = 0.50, h = 0.50 },
botleft = { x = 0.00, y = 0.50, w = 0.50, h = 0.50 },
botright = { x = 0.50, y = 0.50, w = 0.50, h = 0.50 },
maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}
mash = { 'ctrl', 'option', 'cmd' }
hs.hotkey.bind(mash, '.', function() hs.window.focusedWindow():move(units.right25, nil, true) end)
hs.hotkey.bind(mash, ',', function() hs.window.focusedWindow():move(units.left75, nil, true) end)
hs.hotkey.bind(mash, 'l', function() hs.window.focusedWindow():move(units.right50, nil, true) end)
hs.hotkey.bind(mash, 'h', function() hs.window.focusedWindow():move(units.left50, nil, true) end)
hs.hotkey.bind(mash, 'k', function() hs.window.focusedWindow():move(units.top50, nil, true) end)
hs.hotkey.bind(mash, 'j', function() hs.window.focusedWindow():move(units.bot50, nil, true) end)
hs.hotkey.bind(mash, 'u', function() hs.window.focusedWindow():move(units.topleft, nil, true) end)
hs.hotkey.bind(mash, 'i', function() hs.window.focusedWindow():move(units.topright, nil, true) end)
hs.hotkey.bind(mash, 'o', function() hs.window.focusedWindow():move(units.botright, nil, true) end)
hs.hotkey.bind(mash, 'p', function() hs.window.focusedWindow():move(units.botleft, nil, true) end)
hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end)
hs.hotkey.bind(mash, 'z', function()
hs.application.launchOrFocus('Firefox')
hs.eventtap.keyStroke({'cmd'}, "t")
hs.eventtap.keyStrokes("zk")
hs.eventtap.keyStroke({}, "return")
end)
hs.hotkey.bind(mash, 't', function()
hs.application.launchOrFocus('Firefox')
hs.eventtap.keyStroke({'cmd'}, "t")
hs.eventtap.keyStrokes("tk")
hs.eventtap.keyStroke({}, "return")
end)
hs.hotkey.bind(mash, 'n', function()
-- Get the focused window, its window frame dimensions, its screen frame dimensions,
-- and the next screen's frame dimensions.
local focusedWindow = hs.window.focusedWindow()
local focusedScreenFrame = focusedWindow:screen():frame()
local nextScreenFrame = focusedWindow:screen():next():frame()
local windowFrame = focusedWindow:frame()
-- Calculate the coordinates of the window frame in the next screen and retain aspect ratio
windowFrame.x = ((((windowFrame.x - focusedScreenFrame.x) / focusedScreenFrame.w) * nextScreenFrame.w) + nextScreenFrame.x)
windowFrame.y = ((((windowFrame.y - focusedScreenFrame.y) / focusedScreenFrame.h) * nextScreenFrame.h) + nextScreenFrame.y)
windowFrame.h = ((windowFrame.h / focusedScreenFrame.h) * nextScreenFrame.h)
windowFrame.w = ((windowFrame.w / focusedScreenFrame.w) * nextScreenFrame.w)
-- Set the focused window's new frame dimensions
focusedWindow:setFrame(windowFrame)
end)
function focus_app_tab(app, name)
return function()
hs.osascript.javascript([[
(function() {
var brave = Application(']] .. app .. [[');
brave.activate();
for (win of brave.windows()) {
var tabIndex =
win.tabs().findIndex(tab => tab.name().match(/]] .. name .. [[/));
if (tabIndex != -1) {
win.activeTabIndex = (tabIndex + 1);
win.index = 1;
}
}
})();
]])
end
end
-- hs.hotkey.bind({"alt", "cmd"}, "Left", focus_app_tab('Google Chrome', '.*Inbox.*'));
local hyper = { "cmd", "alt" }
local applicationHotkeys = {
space = 'Google Chrome', -- also need to disable the command alt space mac shortcut to search something in finder
v = 'Visual Studio Code',
c = 'Firefox',
d = 'Spotify', -- also need to Turn Dock Hiding Off under launchpad in keyboard settings
f = 'Signal',
}
for key, app in pairs(applicationHotkeys) do
hs.hotkey.bind(hyper, key, function()
hs.application.launchOrFocus(app)
end)
end
-- hs.hotkey.bind(hyper, , focus_app_tab('Firefox', '.*Task List.*'));