-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
181 lines (159 loc) · 5.81 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
-- Return a string containing the connected screens.
function getScreens()
local screens = {}
hs.fnutils.each(hs.screen.allScreens(), function(item)
table.insert(screens, item:name())
end)
return 'Screens: ' .. table.concat(screens, ', ')
end
-- Log text into a file.
function log(data)
local result = tostring(os.date('%Y-%m-%d %H:%M:%S'))
for i, v in ipairs(data) do
result = result .. '\t' .. tostring(v)
end
result = result .. '\n'
file = assert(io.open('console.log', 'a'))
file:write(result)
file:close()
end
-- Load Spoons.
hs.loadSpoon('Seal')
hs.loadSpoon('HoldToQuit')
-- Load custom plugins.
require('config')
require('reload')
require('window')
require('battery')
require('network')
require('caffeine')
require('audio')
-- Bind Reload configs.
hs.hotkey.bind(config.hyper, 'R', reloadWatcherCallback)
-- HoldToQuit configuration.
spoon.HoldToQuit.duration = config.HoldToQuit.duration
spoon.HoldToQuit:init()
spoon.HoldToQuit:start()
-- Seal configuration.
spoon.Seal:bindHotkeys({ show = config.Seal.hotkey })
spoon.Seal:loadPlugins({
'apps',
'pasteboard',
'calc',
'screencapture',
'useractions',
'dateconvert',
'gtranslate',
})
spoon.Seal.chooser:width(45)
spoon.Seal.chooser:placeholderText(config.Seal.placeholder)
spoon.Seal.chooser:searchSubText(true)
spoon.Seal.plugins.useractions.actions = config.Seal.useractions
spoon.Seal.plugins.screencapture.showPostUI = true
spoon.Seal.plugins.gtranslate.key = config.Seal.key
spoon.Seal:refreshAllCommands()
spoon.Seal:start()
-- Window movement.
hs.hotkey.bind(config.hyper, 'Left', windowMove('left'))
hs.hotkey.bind(config.hyper, 'Right', windowMove('right'))
hs.hotkey.bind(config.hyper, 'Up', windowMove('top'))
hs.hotkey.bind(config.hyper, 'Down', windowMove('down'))
-- Bind applications hotkeys.
for key, app in pairs(config.applications) do
hs.hotkey.bind(config.hyper, key, function() hs.application.launchOrFocus(app) end)
end
--[[
By calling here the ping, there's a bigger chance to have it
done when the menu is opened for the first time.
]]--
networkPing()
-- Create the menu.
local menu = hs.menubar.new()
:setTitle(config.menu.icon)
:setMenu(function()
wifi = networkWifiName()
int_ip = networkInternalIP()
ext_ip = networkExternalIP()
caffeine_timers = { { title = 'Indefinitely', fn = caffeineTimerNew(0) } }
if config.menu.caffeine then
for _, item in pairs(config.menu.caffeine) do
table.insert(caffeine_timers, {
title = item.title,
fn = caffeineTimerNew(item.seconds),
})
end
end
local menu = {
{ title = 'Wifi: ' .. wifi, fn = function() hs.pasteboard.setContents(wifi) end },
{ title = networkLabel(), fn = networkPing },
{ title = 'Internal IP: ' .. int_ip, fn = function() hs.pasteboard.setContents(int_ip) end },
{ title = 'External IP: ' .. ext_ip, fn = function() hs.pasteboard.setContents(ext_ip) end },
{ title = '-' },
{
title = 'Stay awake for',
checked = caffeineChecked(),
fn = caffeineToggle,
menu = caffeine_timers,
},
{ title = '-' },
{ title = getScreens() },
}
if config.menu.extended == true then
table.insert(menu, { title = '-' })
table.insert(menu, { title = 'hyper: ' .. table.concat(config.hyper, ' + '), disabled = true })
if config.applications then
for key, app in pairs(config.applications) do
table.insert(menu, { title = app .. ': hyper + ' .. key })
end
table.insert(menu, { title = '-' })
end
table.insert(menu, {
title = 'Window manager',
menu = {
{ title = 'Left: hyper + ←', fn = windowMove('left') },
{ title = 'Left half: hyper + ← + ←', fn = windowMove('left_half') },
{ title = 'Right: hyper + →', fn = windowMove('right') },
{ title = 'Right half: hyper + → + →', fn = windowMove('right_half') },
{ title = 'Top: hyper + ↑', fn = windowMove('top') },
{ title = 'Maximize: hyper + ↑ + ↑', fn = windowMove('full') },
{ title = 'Down: hyper + ↓', fn = windowMove('down') },
{ title = 'Center: hyper + ↓ + ↓', fn = windowMove('center') },
{ title = 'Top Right', fn = windowMove('top_right') },
{ title = 'Top Left', fn = windowMove('top_left') },
{ title = 'DownRight', fn = windowMove('down_right') },
{ title = 'DownLeft', fn = windowMove('down_left') },
}
})
end
return menu
end)
--[[
- sound
MacBook Pro Microphone
MacBook Pro Speakers
Anker SoundCore
- screens
Built-in Retina Display
ZOWIE XL LCD
TV
]]--
-- Force given output device to be always used.
--screenWatcher = hs.screen.watcher.newWithActiveScreen(function(event)
-- if event then
-- local sc = hs.screen.mainScreen():name()
-- print('Current: ' .. sc)
-- -- Set the output to 'Anker SoundCore' if new screen is 'ZOWIE XL LCD'.
-- if sc == 'ZOWIE XL LCD' then
-- if hs.audiodevice.findOutputByName('Anker SoundCore'):setDefaultOutputDevice() then
-- log({ 'Audio: output set to Anker SoundCore.' })
-- end
-- -- Set the output to 'MacBook Pro Speakers' if new screen is 'Built-in Retina Display'.
-- elseif sc == 'Built-in Retina Display' then
-- if hs.audiodevice.findOutputByName('MacBook Pro Speakers'):setDefaultOutputDevice() then
-- log({ 'Audio: output set to MacBook Pro Speakers.' })
-- end
-- end
-- end
--end):start()
--log({ 'Watcher started: Screen.' })
log({ 'init.lua loaded.' })