Skip to content

Instantly share code, notes, and snippets.

@arastu
Last active March 29, 2021 08:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arastu/709473368112208f91b00b16f9a7264a to your computer and use it in GitHub Desktop.
Save arastu/709473368112208f91b00b16f9a7264a to your computer and use it in GitHub Desktop.
Connect/disconnect AirPods automatically on Mac
-- 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