Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Forked from ieatfood/Connect Airpods.applescript
Last active November 15, 2023 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsharp/725fff254801592ea56c3870c158dc72 to your computer and use it in GitHub Desktop.
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.
#!/bin/bash
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)
else
device's closeConnection()
return "Disconnecting " & (device's nameOrAddress as string)
end if
end toggleDevice
return toggleDevice(getFirstMatchingDevice(blueToothDevice))
END
}
if [[ "$1" = "pair" ]]; then
pair
fi
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