1

I'm looking for an external bluetooth button/switch that I can program to do something specific, like open up an app / run a script. Does anything like that exist? Even if it can only do 1 specific thing that would be enough.

closed as off-topic by Allan, Nimesh Neema, Ɱark Ƭ, user3439894, fsb May 30 '18 at 13:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

Not exactly what your looking for but here's a script that will do something when a device is connected.

If you have a speaker (or other Bluetooth device) that connects automatically then you can use the on/off button as a switch.

Credit to Christian Stevenson on SO.

repeat
    set statusOld to checkStatus()
    set statusNew to checkStatus()
    repeat while statusOld is equal to statusNew
        delay 1 --for 1 second checks
        set statusNew to checkStatus()
    end repeat
    if statusNew is true then
        display dialog "Device Added - put some real code here"
    else
        display dialog "Device Removed - put some real code here"
    end if
end repeat

on checkStatus()

    (*Delete the 2 lines below when done testing*)
    --set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
    --set myString to "name: DR-BT101 Connected: " & myString

    (*uncomment line below when done testing*)
    set myString to do shell script "system_profiler SPBluetoothDataType"

    --initial check if it's not even there
    if myString does not contain "[Device Name]" then
        return false
    else

        --find out if connected/disconnected
        set AppleScript's text item delimiters to "name:"
        set myList to the text items of myString --each item of mylist is now one of the devices

        set numberOfDevices to count of myList
        set counter to 1
        repeat numberOfDevices times --loop through each devices checking for Connected string
            if item counter of myList contains "Christian’s AirPods" then
                if item counter of myList contains "Connected: Yes" then
                    return true
                else if item counter of myList contains "Connected: No" then
                    return false
                else
                    display dialog "Error Parsing" --this shouldn't happen
                end if
            end if
            set counter to counter + 1
        end repeat
    end if
end checkStatus
  • Nice find Josh! It might not be an exact fit for the OP's question, but I can already think of a way to adapt this for use in my environment. :) – Monomeeth May 30 '18 at 11:53

Not the answer you're looking for? Browse other questions tagged .