From 36e5025868cfd674ef4f8a0ae0529371d6581572 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Thu, 9 Jul 2026 23:28:49 -0400 Subject: hammerspoon listener pt 1 --- users/ryan/hammerspoon/init.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 users/ryan/hammerspoon/init.lua (limited to 'users/ryan/hammerspoon/init.lua') 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 @@ +-- ~/.hammerspoon/init.lua + +local function refreshWidget() + hs.http.asyncGet("http://127.0.0.1:7776/widget/sound/refresh", nil, function(status, body, headers) + -- optional: log failures + if status ~= 200 then + print("Widget refresh failed with status: " .. tostring(status)) + end + end) +end + +local function audioWatcherCallback(uid, eventName, scope, element) + -- "vmvc" = volume changed, "mute" = mute toggled + if eventName == "vmvc" or eventName == "mute" then + refreshWidget() + end +end + +local function setupAudioWatcher() + local device = hs.audiodevice.defaultOutputDevice() + if device then + device:watcherCallback(audioWatcherCallback) + device:watcherStart() + end +end + +setupAudioWatcher() + +-- Re-attach the watcher if the default output device changes (e.g. plugging in headphones) +hs.audiodevice.watcher.setCallback(function(event) + if event == "dOut " then -- note: the trailing space is intentional, it's part of the event name + setupAudioWatcher() + end +end) +hs.audiodevice.watcher.start() -- cgit v1.3