Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connect/ Disconnect Airpods via Bluetooth. Forked from https://coderwall.com/p/fyfp0w/applescript-to-connect-bluetooth-headphones
activate application "SystemUIServer"
tell application "System Events"
tell process "SystemUIServer"
-- Working CONNECT Script. Goes through the following:
-- Clicks on Bluetooth Menu (OSX Top Menu Bar)
-- => Clicks on SX-991 Item
-- => Clicks on Connect Item
set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
tell btMenu
click
tell (menu item "Airpods" of menu 1)
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 menu was not found, are you already connected?"
end if
end tell
end tell
end tell
end tell
@Acidham

This comment has been minimized.

Copy link

commented Jul 3, 2018

You could move AirPods Name to WF config and us it in script. With that nobody has to edit AppleScript.

unfortunately I cannot pull request on a WF repo

@wxkkeup

This comment has been minimized.

Copy link

commented Jul 4, 2018

Hey, I am having trouble getting this to work. I replaced "AirPods" with the name of my AirPods, but it does not connect for some reason.

@wxkkeup

This comment has been minimized.

Copy link

commented Jul 4, 2018

nevermind. I fixed it by ensuring that my AirPods are the first bluetooth device in the list of bluetooth devices in the menu bar.
screen shot 2018-07-04 at 2 23 00 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.