Closed marceloboeira closed 6 years ago
After reading "Inquiring and Paging" in "Bluetooth Device Access Guide" it doesn't look like a good idea to constantly list devices within range. It may be better to connect to a device and track disconnect.
Though device inquiry could still be done for debugging. Also after looking at bluetooth framework docs, much more functionality can be added like listing paired/favourited/recent devices, getting information about device, connecting/disconnecting devices.
I'd love to be able to disconnect certain devices. I need a way to disconnect my bluetooth headphones when my laptop sleeps.
I've added some functionality on dev branch. Not yet sure if it can be considered final.
@marceloboeira Probably calling blueutil --connect ADDRESS
and doing something on failure exit. Other option is to add functionality for reacting on disconnect notification, but then the connection should be kept open.
@twe4ked blueutil --disconnect ADDRESS
Thanks @toy! I'll give it a go.
Works fantastically.
This is how I'm using it:
#!/bin/bash -e
#
# https://github.com/toy/blueutil
NAME=QC35
CONNECTION_STRING="$(blueutil --paired | grep $NAME)"
ADDRESS="$(echo "$CONNECTION_STRING" | cut -d' ' -f 2 | sed 's/,//')"
if [[ "$CONNECTION_STRING" = *"not connected"* ]]; then
blueutil --connect "$ADDRESS"
else
blueutil --disconnect "$ADDRESS"
fi
@twe4ked So you wanted an ability to toggle connection with headphones?
I've already added ability to get information about one device and get connected status and though of ability to find device by name (in the list of recently connected devices)
So you wanted an ability to toggle connection with headphones?
That was just my test script for now. My plan is to disconnect my headphones when my laptop sleeps and reconnect on wake (this might happen automatically, not sure). Otherwise my headphones stay connected when I'm commuting and have to manually disconnect them to use my iPhone.
Edit: --info
and --is-connected
look great!
How about listing the devices within range of your Mac? Its always nice for debugging or even scripting...
e.g.: I thinking about locking my Mac every time my iPhone (over bluetooth) is not in range....