aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/hammerspoon/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/hammerspoon/init.lua')
-rw-r--r--users/ryan/hammerspoon/init.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/users/ryan/hammerspoon/init.lua b/users/ryan/hammerspoon/init.lua
new file mode 100644
index 0000000..1245a09
--- /dev/null
+++ b/users/ryan/hammerspoon/init.lua
@@ -0,0 +1,35 @@
1-- ~/.hammerspoon/init.lua
2
3local function refreshWidget()
4 hs.http.asyncGet("http://127.0.0.1:7776/widget/sound/refresh", nil, function(status, body, headers)
5 -- optional: log failures
6 if status ~= 200 then
7 print("Widget refresh failed with status: " .. tostring(status))
8 end
9 end)
10end
11
12local function audioWatcherCallback(uid, eventName, scope, element)
13 -- "vmvc" = volume changed, "mute" = mute toggled
14 if eventName == "vmvc" or eventName == "mute" then
15 refreshWidget()
16 end
17end
18
19local function setupAudioWatcher()
20 local device = hs.audiodevice.defaultOutputDevice()
21 if device then
22 device:watcherCallback(audioWatcherCallback)
23 device:watcherStart()
24 end
25end
26
27setupAudioWatcher()
28
29-- Re-attach the watcher if the default output device changes (e.g. plugging in headphones)
30hs.audiodevice.watcher.setCallback(function(event)
31 if event == "dOut " then -- note: the trailing space is intentional, it's part of the event name
32 setupAudioWatcher()
33 end
34end)
35hs.audiodevice.watcher.start()