Skip to content

Instantly share code, notes, and snippets.

@jaredmoody
Last active December 9, 2021 13:11
Show Gist options
  • Save jaredmoody/fad52569fafe5c7d2597edbc18696547 to your computer and use it in GitHub Desktop.
Save jaredmoody/fad52569fafe5c7d2597edbc18696547 to your computer and use it in GitHub Desktop.
An Applescript to connect bluetooth devices, such as Airpods. Nice when paired with an alfred trigger.
# Don't use this script, use this one instead:
# https://gist.github.com/ieatfood/814b065964492f71f728da59a47413bc
tell application "System Events"
tell process "ControlCenter"
set bt to (first menu bar item whose title is "Bluetooth") of menu bar 1
click bt
set btCheckbox to checkbox 1 of scroll area 1 of group 1 of window "Control Center" whose title contains "AirPods Pro"
set btCheckboxValue to value of btCheckbox
tell btCheckbox to click
tell bt to click
end tell
end tell
@jaredmoody
Copy link
Author

My pleasure - thanks for the tip!

@ieatfood
Copy link

I found a more elegant script, using IOBluetooth framework instead of menu clicks, so it should work in other languages or if Apple updates the menus.

https://gist.github.com/ieatfood/814b065964492f71f728da59a47413bc

by https://github.com/smithumble

@jaredmoody
Copy link
Author

Yep, that one is better, thanks!

@verheyenkoen
Copy link

Brilliant! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment