Last active
March 29, 2021 08:47
-
-
Save arastu/709473368112208f91b00b16f9a7264a to your computer and use it in GitHub Desktop.
Connect/disconnect AirPods automatically on Mac
This file contains hidden or 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
-- Forked from: https://coderwall.com/p/fyfp0w/applescript-to-connect-bluetooth-headphones | |
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 "PUT_YOUR_AIRPODE_NAME_HERE" of menu 1) -- Touhid’s AirPods not Touhid's AirPods | |
click | |
if exists menu item "Connect" of menu 1 then | |
click menu item "Connect" of menu 1 | |
return "Connecting..." | |
else if exists menu item "Disconnect" of menu 1 then | |
click menu item "Disconnect" of menu 1 | |
return "Disconnecting..." | |
else | |
click btMenu -- Close main BT drop down if Connect wasn't present | |
return "Connect/disconncet menu was not found" | |
end if | |
end tell | |
end tell | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment