Skip to content

Instantly share code, notes, and snippets.

Forked from ieatfood/Connect Airpods.applescript
Last active November 15, 2023 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davidsharp/725fff254801592ea56c3870c158dc72 to your computer and use it in GitHub Desktop.
A xbar/bitbar wrapper around an Applescript to connect bluetooth devices, such as Airpods.
function pair(){
osascript <<'END'
use framework "IOBluetooth"
use scripting additions
set blueToothDevice to "Buds Pro"
on getFirstMatchingDevice(deviceName)
repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
if (device's nameOrAddress as string) contains deviceName then return device
end repeat
end getFirstMatchingDevice
on toggleDevice(device)
if not (device's isConnected as boolean) then
device's openConnection()
return "Connecting " & (device's nameOrAddress as string)
device's closeConnection()
return "Disconnecting " & (device's nameOrAddress as string)
end if
end toggleDevice
return toggleDevice(getFirstMatchingDevice(blueToothDevice))
if [[ "$1" = "pair" ]]; then
echo "ᚼᛒ|bash=$0 param1=pair terminal=false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment