Skip to content

Instantly share code, notes, and snippets.

@spinscale
Created April 16, 2017 18:19
Show Gist options
  • Save spinscale/fd82f00da29447990f27f36b3f4b927d to your computer and use it in GitHub Desktop.
Save spinscale/fd82f00da29447990f27f36b3f4b927d to your computer and use it in GitHub Desktop.
Hammerspoon: Configure volume via keyboard shortcuts for macbook pro (touchbar, but no keys)
function changeVolume(diff)
return function()
local current = hs.audiodevice.defaultOutputDevice():volume()
local new = math.min(100, math.max(0, math.floor(current + diff)))
if new > 0 then
hs.audiodevice.defaultOutputDevice():setMuted(false)
end
hs.alert.closeAll(0.0)
hs.alert.show("Volume " .. new .. "%", {}, 0.5)
hs.audiodevice.defaultOutputDevice():setVolume(new)
end
end
hs.hotkey.bind({'ctrl', 'alt', 'cmd'}, 'Down', changeVolume(-3))
hs.hotkey.bind({'ctrl', 'alt', 'cmd'}, 'Up', changeVolume(3))
Copy link

ghost commented May 11, 2021

Thanks so much

@zhangkai803
Copy link

works perfectly on my mechine, macOS 13.3.1, Hammerspoon 0.9.100.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment