Created
August 3, 2016 22:03
-
-
Save jneubrand/473e9eb90d66ebb467e217a07492129a to your computer and use it in GitHub Desktop.
A hammerspoon snippet that lets you hyper-scroll to change your output volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local volumeBeep = hs.sound.getByName('Pop') | |
local volumeText | |
local volumeTextTimer | |
function hideVolumeText() | |
if volumeText then | |
volumeText:hide(0.1) | |
end | |
end | |
hs.eventtap.new({hs.eventtap.event.types.scrollWheel}, function(e) | |
local mods = hs.eventtap.checkKeyboardModifiers() | |
if mods.alt and mods.ctrl and mods.shift then | |
delta = e:getProperty( | |
hs.eventtap.event.properties.scrollWheelEventDeltaAxis1) | |
hs.audiodevice.defaultOutputDevice():setVolume( | |
hs.audiodevice.defaultOutputDevice():volume() - delta | |
) | |
local newVolume = | |
math.floor(hs.audiodevice.defaultOutputDevice():volume()) | |
local speakerEmoji | |
if newVolume > 60 then | |
speakerEmoji = '🔊' | |
elseif newVolume > 40 then | |
speakerEmoji = '🔉' | |
elseif newVolume > 0 then | |
speakerEmoji = '🔈' | |
else | |
speakerEmoji = '🔇' | |
end | |
if not volumeText then | |
volumeText = hs.drawing.text(hs.geometry.rect(20, 35, 200, 200), '') | |
volumeText:setLevel(hs.drawing.windowLevels.cursor + 1) | |
volumeText:setTextColor({1, 0, 0}) | |
end | |
volumeText:setText(speakerEmoji .. ' ' .. tostring(newVolume) .. '%') | |
volumeText:show() | |
if not volumeTextTimer then | |
volumeTextTimer = hs.timer.delayed.new(1, hideVolumeText) | |
end | |
volumeTextTimer:start() | |
return true | |
end | |
end):start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment