lapfelix / BluetoothConnector

Simple macOS CLI to connect/disconnect a Bluetooth device. Useful for AirPods or other Bluetooth headphones.
MIT License
531 stars 34 forks source link

disconnecting doesn't seem to be working if not passing --notify under Monterey #20

Open godbout opened 2 years ago

godbout commented 2 years ago

weird, i know. but it seems to be the case. whether passing the --disconnect flag or not. adding --notify fixes it, but, well, notification.

alphabitnz commented 2 years ago

disconnect not working for me either, even if i pass --notify. Monterey 12.1 Beta (21C5039b)

CHigginbotham commented 2 years ago

I am also experiencing this issue. Adding notify simply makes it say that it was successful in disconnecting. when checking the devices in settings it becomes apparent this is not the case.

Works fine for connecting. However will not connect if bluetooth is disabled. Spawns error saying failed to enable bluetooth.

As a workaround in the meantime I am just completely disabling bluetooth. Not ideal, no but if you don't need it for other things, it works.

Here's what I use for disabling bluetooth: blueutil Link: https://github.com/toy/blueutil

(Disable): blueutil -p 0 (Enable): blueutil -p 1

--------Debug Info-------- Monterey 12.0.1 2018 MacBook Pro 15" Intel Core i7, 2.6 GHz 1 TB 16GB RAM

BluetoothConnector Version: 2.0.0

alphabitnz commented 2 years ago

As a workaround in the meantime I am just completely disabling bluetooth. Not ideal, no but if you don't need it for other things, it works.

Here's what I use for disabling bluetooth: blueutil Link: https://github.com/toy/blueutil

Good tip there about blueutil, also I found something for you on their issues page - instead of disabling bluetooth you can use their disconnect function which I can confirm is working if you use the following syntax (replace 24-d0-df-85-28-62 with your device's MAC):

blueutil --disconnect '24-d0-df-85-28-62' --wait-disconnect '24-d0-df-85-28-62'

Hopefully this info may assist BluetoothConnector devs with a workaround for their tool also

CHigginbotham commented 2 years ago

Wow thanks for the tip! It works! I think I tried that a while back and must not have been doing it properly.

luckman212 commented 2 years ago

Ouch, same issue here. Hope a fix is discovered - use this all the time in Alfred...

edit: I made a small patch to fix compilation error, #21 but even compiling with latest tools (using M1 Mac Mini on 12.1 / Xcode 13.2.1) did not fix this issue. I looked at the code and can't see anything obviously wrong, so maybe just a bug in IOBluetooth

lapfelix commented 2 years ago

Didn't mean to close this issue. I could reproduce. Not sure what's causing the problem here though. IOBluetoothDevice's closeConnection() just doesn't seem to do what it's supposed to do (and returns kIOReturnSuccess!)

lapfelix commented 2 years ago

What Bluetooth devices are you folks having issues with? Is it AirPods? I just tried with macOS 12.3 (the first beta, build 21E5196i) and after disconnecting with BluetoothConnector my AirPods would often reconnect. Once I disabled the AirPods' automatic connection feature, --disconnect seems to work perfectly.

Might be because Apple fixed a but with Core Bluetooth in macOS 12.3, of it's an issue that only applies to AirPods and disabling the automatic connection fixes it (when "Connect to This Mac" is set to "When Last Connected to This Mac" in the Bluetooth settings).

godbout commented 2 years ago

in my case AirPods (Pro) yeah.

alphabitnz commented 2 years ago

for me it was Logitech Z337 speakers

luckman212 commented 2 years ago

@lapfelix I double checked, but already had my AirPods set to only reconnect when last connected. Just re-tested on 12.2.

lapfelix commented 2 years ago

Okay that's good news then, it means 12.3 probably fixes the issue everyone's been encountering with disconnections.

alphabitnz commented 2 years ago

I am now on 12.3 Beta (21E5196i) and blueutil was still experiencing the disconnect bug unless I passed the --wait-disconnect stuff as per the workaround, so possiblynot fixed by 12.3 as hoped.

I could test with bluetoothconnector but have run out of time for today

godbout commented 2 years ago

some people seem to have the issue still on 12.3.1. anybody here? works fine for me.

kaqijiang commented 2 years ago

I used it to solve my problem blueutil Link: https://github.com/toy/blueutil

image

image
srescio commented 1 year ago

hi am on Monterey 12.5.1 (21G83) and needed the mentioned workaround or it wouldn't disconnect

pjv commented 1 year ago

On 12.6.1 no disconnect whether passing --notify or not.

The blueutil --disconnect --wait-disconnect is working.

jibminJung commented 1 year ago

image on ventura 13.0 still doesn't work. to toggle connection with bluetooth device i used automator, BluetoothConnector and blueutil. blueutil's disconnect works

godbout commented 1 year ago

if i'm not wrong now in my case on 13.2 (but probably 13.1 too) nothing works anymore 😂️ connection or disconnection.

orthand commented 1 year ago

if i'm not wrong now in my case on 13.2 (but probably 13.1 too) nothing works anymore 😂️ connection or disconnection.

Blueutil was updated in January and (dis-)connecting works for me on 13.2.1 in case anybody is still looking for a (currently working) solution.

lapfelix commented 10 months ago

I added a retry feature when disconnecting with 2.1.0