Skip to content

Instantly share code, notes, and snippets.

@numbcoder
Created April 4, 2022 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numbcoder/68d211754f010cfb90153dbcf544e806 to your computer and use it in GitHub Desktop.
Save numbcoder/68d211754f010cfb90153dbcf544e806 to your computer and use it in GitHub Desktop.
Connect to AirPods for hammerspoon
-- connected to AirPods by name
function connectToAirPods(name)
local current = hs.audiodevice.defaultInputDevice()
if current and current:name() == name then return true end
local device = hs.audiodevice.findOutputByName(name)
if device == nil then
hs.alert.show(name.." is not connected")
else
return device:setDefaultOutputDevice()
end
end
-- keymap
hs.hotkey.bind({"ctrl", "cmd"}, "p", function() connectToAirPods("Tim’s AirPods Pro") end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment