5

I am struggling to find some (elegant) way to connect my Mac to a (previously paired) Bluetooth device via terminal.


There is a solution using Applescript simulating mouse clicks, but it has some major issues:

  • Bluetooth menu needs to be visible in the Menu bar
  • Terminal needs access to the Accessibility Controls
  • Does not work reliably
  • It is slow as hell
  • When you use the mouse while the script is running, it fails.

So, this is more or less a no-go..


I don't need to switch Bluetooth on and off in general, I don't need any pairing mechanism, I just need some way to trigger the connection to known devices via terminal.

My use case is a Bluetooth Sound Module - for example I called it "NoiseBox". What I want is this:

./magic-script.sh connect NoiseBox

or

./magic-script.sh disconnect NoiseBox 

Can you help me?

PS: Is it possible to write some small Application in Swift or ObjC which does this?

migrated from superuser.com Sep 15 '16 at 11:38

This question came from our site for computer enthusiasts and power users.

  • I use a non-elegant way at the time with "cliclick" which at least is much faster than the AppleScript from Andrew Burns but is really not elegant. cliclick clicks the Bluetooth menu and does some arrow-down clicks then arrow-right and a return. Not very beautiful but it works. – franc Nov 17 '17 at 21:09
2

As there are some upvotes and many views, I will answer my own question there:

Yes, it is possible to write some small application in Swift or ObjC which does this. And some people did that already:

BluetoothConnector is written in Swift, which does (currently) only support connecting and disconnecting (It seems to be pretty new, so more features may follow some day).

blueutil is written in Objective-C. In addition to (dis-)connecting it can also toggle power, discoverability, show if you are already connected, etc.

I tried both, and both worked well, currently I'll stick with blueutil - it has more features, which come in handy in shell scripts.

You must log in to answer this question.

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