-
Notifications
You must be signed in to change notification settings - Fork 0
/
openconnect.lua
34 lines (29 loc) · 1.1 KB
/
openconnect.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
local mymodule = {}
function printf(s,...) print(s:format(...)) end
-- restart openconnect with a shell script
function restart()
-- Add the following line to /etc/sudoers to reduce password prompt of sudo /opt/bin/openconnect.sh
-- %admin ALL=(ALL) NOPASSWD: /opt/bin/openconnect.sh
-- The reason nohup is used is that openconnect might output content to stdin continuously, which might make hammerspoon hung.
local output = hs.execute("nohup sudo /opt/bin/openconnect.sh > /dev/null 2>&1 &", false)
printf("openconnect restarted.")
hs.notify.new({title="Openconnect", informativeText="openconnect restarted"}):send()
return output
end
-- mod.listenOnHotkey({{"cmd", "alt", "ctrl"}, "V"})
function mymodule.listenOnHotkey(keyspec)
hs.hotkey.bindSpec(keyspec, function()
restart()
end)
end
-- mod.listenOnEvent()
function mymodule.listenOnWakeEvent()
wather = hs.caffeinate.watcher.new(function(eventType)
-- screensDidWake, systemDidWake, screensDidUnlock
if eventType == hs.caffeinate.watcher.systemDidWake then
restart()
end
end)
wather:start()
end
return mymodule