Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Forked from ieatfood/Connect Airpods.applescript
Last active November 12, 2024 17:36
Show Gist options
  • Select an option

  • Save davidsharp/725fff254801592ea56c3870c158dc72 to your computer and use it in GitHub Desktop.

Select an option

Save davidsharp/725fff254801592ea56c3870c158dc72 to your computer and use it in GitHub Desktop.

Revisions

  1. davidsharp revised this gist Nov 15, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bluetooth.10s.sh
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@ if [[ "$1" = "pair" ]]; then
    pair
    fi

    echo "BT|bash=$0 param1=pair terminal=false"
    echo "ᚼᛒ|bash=$0 param1=pair terminal=false"
  2. davidsharp revised this gist Nov 15, 2023. No changes.
  3. davidsharp renamed this gist Nov 15, 2023. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions Connect Airpods.applescript → bluetooth.10s.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    # Taken from https://www.reddit.com/r/MacOS/comments/i4czgu/big_sur_airpods_script/gck3gz3/
    # by https://github.com/smithumble
    #!/bin/bash

    function pair(){
    osascript <<'END'
    use framework "IOBluetooth"
    use scripting additions
    set AirPodsName to "AirPods"
    set blueToothDevice to "Buds Pro"
    on getFirstMatchingDevice(deviceName)
    repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
    @@ -22,4 +23,11 @@ on toggleDevice(device)
    end if
    end toggleDevice
    return toggleDevice(getFirstMatchingDevice(AirPodsName))
    return toggleDevice(getFirstMatchingDevice(blueToothDevice))
    END
    }
    if [[ "$1" = "pair" ]]; then
    pair
    fi

    echo "BT|bash=$0 param1=pair terminal=false"
  4. @ieatfood ieatfood revised this gist Jun 27, 2021. 1 changed file with 25 additions and 10 deletions.
    35 changes: 25 additions & 10 deletions Connect Airpods.applescript
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,25 @@
    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
    # Taken from https://www.reddit.com/r/MacOS/comments/i4czgu/big_sur_airpods_script/gck3gz3/
    # by https://github.com/smithumble

    use framework "IOBluetooth"
    use scripting additions

    set AirPodsName to "AirPods"

    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(AirPodsName))
  5. @jaredmoody jaredmoody revised this gist Dec 11, 2020. 1 changed file with 8 additions and 17 deletions.
    25 changes: 8 additions & 17 deletions Connect Airpods.applescript
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,10 @@
    activate application "SystemUIServer"
    tell application "System Events"
    tell process "SystemUIServer"
    set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
    tell btMenu
    click
    tell (menu item "Jared's AirPods" of menu 1)
    click
    if exists menu item "Connect" of menu 1 then
    click menu item "Connect" of menu 1
    return "Connecting..."
    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
    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
    end tell
  6. @jaredmoody jaredmoody created this gist Nov 7, 2018.
    19 changes: 19 additions & 0 deletions Connect Airpods.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    activate application "SystemUIServer"
    tell application "System Events"
    tell process "SystemUIServer"
    set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
    tell btMenu
    click
    tell (menu item "Jared's AirPods" of menu 1)
    click
    if exists menu item "Connect" of menu 1 then
    click menu item "Connect" of menu 1
    return "Connecting..."
    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