Skip to content

Instantly share code, notes, and snippets.

@smartkiwi
Created January 25, 2022 04:34
Show Gist options
  • Save smartkiwi/b1e670f67b8ccf75ebacfd4e678cc75f to your computer and use it in GitHub Desktop.
Save smartkiwi/b1e670f67b8ccf75ebacfd4e678cc75f to your computer and use it in GitHub Desktop.
Griffin Powermate Mute with the LED
--- based on https://github.com/cedstrom/powermate-osx
--- https://raw.githubusercontent.com/cedstrom/powermate-osx/main/knob.lua
--- https://github.com/Hammerspoon/Spoons/blob/master/Source/MicMute.spoon/init.lua#L28
hs.loadSpoon("MicMute")
spoon.MicMute:bindHotkeys(
{
toggle = {
{"cmd", "shift"}, "M"
}
},
0.75)
powermate =
hs.distributednotifications.new(
function(name, object, userInfo)
-- print(string.format("name: %s\nobject: %s\nuserInfo: %s\n", name, object, hs.inspect(userInfo)))
if object == "kPowermateKnobPress" then
spoon.MicMute.toggleMicMute()
local mic = hs.audiodevice.defaultInputDevice()
if mic:muted() then
print("muted")
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDLevel", level=1.0})
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDOn"})
else
print("on")
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDOff"})
end
elseif object == "kPowermateKnobClockwise" then
device = hs.audiodevice.defaultOutputDevice()
currentVolume = device:outputVolume() + 1;
device:setOutputVolume(currentVolume)
elseif object == "kPowermateKnobCounterClockwise" then
device = hs.audiodevice.defaultOutputDevice()
currentVolume = device:outputVolume() - 1;
device:setOutputVolume(currentVolume)
end
end,
"kPowermateKnobNotification"
)
powermate:start()
-- ramp the led, flash it slow, flash it quickly, turn it off.
for i=0,1,0.1
do
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDLevel", level=i})
hs.timer.usleep(250000);
end
hs.timer.doAfter(1,
function()
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDFlash", level=15})
hs.timer.doAfter(10,
function()
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDFlash", level=32})
hs.timer.doAfter(2,
function()
hs.distributednotifications.post("kPowermateLEDNotification", "org.hammerspoon", { fn = "kPowermateLEDOff"})
end
)
end
)
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment