Created
November 27, 2018 15:34
-
-
Save daGrevis/79b27b9c156ba828ad52976a118b29e0 to your computer and use it in GitHub Desktop.
Hammerspoon + AirPods
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
function airPods(deviceName) | |
local s = [[ | |
activate application "SystemUIServer" | |
tell application "System Events" | |
tell process "SystemUIServer" | |
set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth") | |
tell btMenu | |
click | |
]] | |
.. | |
'tell (menu item "' .. deviceName .. '" of menu 1)\n' | |
.. | |
[[ | |
click | |
if exists menu item "Connect" of menu 1 then | |
click menu item "Connect" of menu 1 | |
return "Connecting AirPods..." | |
else | |
click menu item "Disconnect" of menu 1 | |
return "Disconecting AirPods..." | |
end if | |
end tell | |
end tell | |
end tell | |
end tell | |
]] | |
return hs.osascript.applescript(s) | |
end | |
hs.hotkey.bind({"cmd"}, "\\", function() | |
local ok, output = airPods('daGrevis’ AirPods') | |
if ok then | |
hs.alert.show(output) | |
else | |
hs.alert.show("Couldn't connect to AirPods!") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment