Skip to content

Instantly share code, notes, and snippets.

@jrejaud
Created July 3, 2018 01:40
Show Gist options
  • Save jrejaud/5427e3dc7fb32f0cd32f0e8cdf5949fa to your computer and use it in GitHub Desktop.
Save jrejaud/5427e3dc7fb32f0cd32f0e8cdf5949fa to your computer and use it in GitHub Desktop.
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
Copy link

Acidham 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
Copy link

wxkkeup 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
Copy link

wxkkeup 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