-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
171 lines (144 loc) · 5.22 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
-- VARIABLES
local caffeine = require("caffeine")
local reloadWatcher = nil
local appWatcher = nil
local screenWatcher = nil
hs.window.animationDuration = 0
hs.grid.MARGINX = 0
hs.grid.MARGINY = 0
hs.grid.GRIDWIDTH = 4
hs.grid.GRIDHEIGHT = 2
-- FUNCTIONS
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
function spotifyTrack()
if not hs.spotify.isPlaying() then
return
end
local artist = hs.spotify.getCurrentArtist() or "Unknown artist"
local album = hs.spotify.getCurrentAlbum() or "Unknown album"
local track = hs.spotify.getCurrentTrack() or "Unknown track"
local trackInfo = {
title=track,
subTitle=artist,
informativeText=album,
}
local _cmd = 'tell application "Spotify" to artwork url of the current track'
local ok, imageURL = hs.applescript.applescript(_cmd)
if ok then
trackInfo.contentImage = hs.image.imageFromURL(imageURL)
end
local notification = hs.notify.new(trackInfo)
notification:send()
hs.timer.doAfter(3, function () notification:withdraw() end)
end
function toggleKeyboardLayout()
us = "U.S."
ca = "Canadian French - CSA"
if hs.keycodes.currentLayout() == us then
hs.keycodes.setLayout(ca)
else
hs.keycodes.setLayout(us)
end
end
function leftSplit()
local win = hs.window.frontmostWindow()
local w = hs.grid.GRIDWIDTH/2
local h = hs.grid.GRIDHEIGHT
hs.grid.set(win, hs.geometry(0, 0, w, h))
end
function rightSplit()
local win = hs.window.frontmostWindow()
local w = hs.grid.GRIDWIDTH/2
local h = hs.grid.GRIDHEIGHT
hs.grid.set(win, hs.geometry(w, 0, w, h))
end
function appWatcherCallback(name, event, app)
end
function applyDeskLayout(version)
local macbookMonitor = "Built-in Retina Display"
local centerMonitor = "LF32TU87"
local rightMonitor = "S2719DGF"
local deskLayoutWeb = {
{"Chrome", nil, centerMonitor, hs.layout.left75, nil, nil},
{"iTerm2", nil, centerMonitor, hs.layout.right25, nil, nil},
{"Workplace Chat", nil, rightMonitor, hs.geometry.rect(0, 0.5, 1, 0.5), nil, nil},
{"Mattermost", nil, rightMonitor, hs.geometry.rect(0, 0, 1, 0.5), nil, nil},
{"VS Code", nil, macbookMonitor, hs.layout.maximized, nil, nil},
{"Spotify", nil, macbookMonitor, hs.layout.maximized, nil, nil},
}
local deskLayoutCode = {
{"Chrome", nil, macbookMonitor, hs.layout.maximized, nil, nil},
{"iTerm2", nil, centerMonitor, hs.layout.right25, nil, nil},
{"Workplace Chat", nil, rightMonitor, hs.geometry.rect(0, 0.5, 1, 0.5), nil, nil},
{"Mattermost", nil, rightMonitor, hs.geometry.rect(0, 0, 1, 0.5), nil, nil},
{"VS Code", nil, centerMonitor, hs.layout.left75, nil, nil},
{"Spotify", nil, macbookMonitor, hs.layout.maximized, nil, nil},
}
-- mac
hs.application.launchOrFocus("Spotify")
hs.application.launchOrFocus("VS Code @ Meta")
-- right
hs.application.launchOrFocus("Workplace Chat")
hs.application.launchOrFocus("Mattermost")
-- center
hs.application.launchOrFocus("Google Chrome")
hs.application.launchOrFocus("iTerm2")
if hs.screen.find(centerMonitor) ~= nil and hs.screen.find(rightMonitor) then
if version == "web" then
hs.layout.apply(deskLayoutWeb)
end
if version == "code" then
hs.layout.apply(deskLayoutCode)
end
end
vscode = hs.application.get("VS Code @ Meta"):mainWindow():raise()
chrome = hs.application.get("Google Chrome"):mainWindow():raise()
spotify = hs.application.get("Spotify"):mainWindow():sendToBack()
end
function applyDeskLayoutWeb()
applyDeskLayout("web")
end
function applyDeskLayoutCode()
applyDeskLayout("code")
end
-- WATCHERS + SERVICES
caffeine:start()
reloadWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
appWatcher = hs.application.watcher.new(appWatcherCallback):start()
screenWatcher = hs.screen.watcher.new(applyDeskLayoutWeb):start()
-- KEYS
shortmod = {"ctrl", "cmd"}
fullmod = {"ctrl", "alt", "cmd"}
-- BINDS
hs.hotkey.bind(shortmod, "M", hs.grid.maximizeWindow)
hs.hotkey.bind(shortmod, "H", hs.grid.pushWindowLeft)
hs.hotkey.bind(shortmod, "J", hs.grid.pushWindowDown)
hs.hotkey.bind(shortmod, "K", hs.grid.pushWindowUp)
hs.hotkey.bind(shortmod, "L", hs.grid.pushWindowRight)
hs.hotkey.bind(shortmod, "Y", hs.grid.resizeWindowThinner)
hs.hotkey.bind(shortmod, "U", hs.grid.resizeWindowShorter)
hs.hotkey.bind(shortmod, "I", hs.grid.resizeWindowTaller)
hs.hotkey.bind(shortmod, "O", hs.grid.resizeWindowWider)
hs.hotkey.bind(shortmod, "[", hs.grid.pushWindowPrevScreen)
hs.hotkey.bind(shortmod, "]", hs.grid.pushWindowNextScreen)
hs.hotkey.bind(shortmod, "A", leftSplit)
hs.hotkey.bind(shortmod, "D", rightSplit)
hs.hotkey.bind(fullmod, "1", applyDeskLayoutWeb)
hs.hotkey.bind(fullmod, "2", applyDeskLayoutCode)
hs.hotkey.bind(fullmod, "L", hs.caffeinate.startScreensaver)
hs.hotkey.bind(fullmod, "S", spotifyTrack)
hs.hotkey.bind(fullmod, "K", toggleKeyboardLayout)
hs.hotkey.bind(fullmod, "C", function () hs.application.launchOrFocus("Google Chrome") end)
hs.hotkey.bind(fullmod, "I", function () hs.application.launchOrFocus("iTerm2") end)
-- YEY, everything's been loaded
hs.alert.show("hammerspoon ready!")