8

I want to disconnect a connection to a bluetooth device through an Applescript. Please note that I don't want to disable or enable bluetooth, I just want to disable one specific connection.

3 Answers 3

4

Here is what I use for disconnecting my Samsung Soundbar. Also remember that you need to give permission to application to use SystemUIServer steps for that.

System Preferences > Security & Privacy > Accessibility > [name_of_your_application]

One little remark: you need to have bluetooth icon on your menu bar.

tell application "System Events" to tell process "SystemUIServer"
    set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
    click bt
    tell (first menu item whose title is "[Samsung] Soundbar") of menu of bt
        click
        tell menu 1
            if exists menu item "Disconnect" then
                click menu item "Disconnect"
            else
                click bt -- close main dropdown to clean up after ourselves
            end if
        end tell
    end tell
end tell
1
  • Works well. I wouldn't have thought to do it via the menu bar, but it works great. Thanks man. Mar 17, 2017 at 0:18
1

Bluetooth functionality isn't made available through the Mac OS APIs (System Events being the chief one for things like this). You should be able to do this with GUI scripting (a great intro can be found on the Mac OS X automation site), but this is a really wonky way of doing it and is error-prone (unexpected dialog windows being the single biggest problem).

1

Not sure if this will work, my bluetooth has been b0rk3d for quite some time, but

man networksetup

You should be able to say something like

networksetup -getInfo <interface>

and then you could use the vast array of tragically randomly capitalized switches to work your will upon your bluetooth device, which should be a network interface.

OR

You want to disable one connection, and one connection alone?

/sbin/ipfw -q add deny ip from <bluetooth interface> to [any|badguy.com]
1
  • 1
    I don't think this is the correct way. I'm not talking about a bluetooth PAN or something like this. I refer to a simple bluetooth connection between a Human-Input Device (HID) and my Macbook.
    – jsadfeew
    Feb 15, 2011 at 7:38

You must log in to answer this question.

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