Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--recent and --favourites not working on macOS Monterey #63

Closed
friedrichweise opened this issue Dec 11, 2021 · 10 comments
Closed

--recent and --favourites not working on macOS Monterey #63

friedrichweise opened this issue Dec 11, 2021 · 10 comments

Comments

@friedrichweise
Copy link
Contributor

I'm the developer of wechsel and experiencing some issues in macOS Monterey. I'm using the last Intel Macbook from 2015, that actually supports macOS 12.
Running the following blueutil-command always returns an empty list:

$ blueutil --recent
$ blueutil --favourites

At wechsel I'm using the following Swift code to access the devices. Using recentDevices() or favoriteDevices() – either way the device list is empty:

guard var devices = IOBluetoothDevice.recentDevices(0) as? [IOBluetoothDevice] else {
            print("Error accessing IOBluetoothDevice.recentDevices")
            return []
}

There seems to be a problem with the IOBluetooth framework on Monterey. Anyone experiencing similar issues?

@toy
Copy link
Owner

toy commented Dec 11, 2021

Simplest way to check is by using a script in swift:

#!/usr/bin/env swift

import IOBluetooth

print(IOBluetoothDevice.favoriteDevices()!)
print(IOBluetoothDevice.recentDevices(3)!)

Can you check if it is related to permissions as in #60?

@friedrichweise
Copy link
Contributor Author

The scripts returns two empty arrays:

$ ./test.swift
[]
[]

I've read Issue #60 and added the Terminal to the "Developer Tools" privacy section. This doesn’t affect the behaviour. Is there an elegant way to get the full system log using the Console.app or a similar tool?

@toy
Copy link
Owner

toy commented Dec 12, 2021

Can you try adding the Bluetooth privacy setting (and restart Terminal)?

For system log there is log command, but it may be tricky to filter for such case. For example everything on all levels containing case insensitive blue: log stream --level debug --color always --timeout 10s | grep -i blue.

@friedrichweise
Copy link
Contributor Author

Alright. I added the Terminal (and also iTerm2 – my primary terminal) to the Bluetooth and the Developer Tools privacy settings. Then run blueutil --favorites. Given your log command I get the following output:

blueutil: (libsystem_info.dylib) Retrieve User by ID
bluetoothd: [com.apple.bluetooth:Server.Core] PowerManager power state is 1
bluetoothd: [com.apple.bluetooth:Server.Core] PowerManager power state is 1
bluetoothd: [com.apple.bluetooth:Server.A2DP] No corresponding device for DF963AC9 found in fA2dpHandleToDeviceMap (0 devices)
bluetoothd: [com.apple.bluetooth:Server.A2DP] isStreamingAudioToDevice: Unable to retrieve handle for device.
bluetoothd: [com.apple.bluetooth:Server.A2DP] No corresponding device for 994ABEEE found in fA2dpHandleToDeviceMap (0 devices)
bluetoothd: [com.apple.bluetooth:Server.A2DP] isStreamingAudioToDevice: Unable to retrieve handle for device.
bluetoothd: [com.apple.bluetooth:Server.MacCoex] Posting Bluetooth Status Notification <private>
studentd: (ClassroomKit) [com.apple.classroom:Bluetooth] entered finishedRescanInterval
PerfPowerServices: (CoreBluetooth) [com.apple.bluetooth:CoreBluetooth] -[CBClassicManager retrievePairedPeersWithOptions:] <private>
PerfPowerServices: (CoreBluetooth) [com.apple.bluetooth:CoreBluetooth] -[CBClassicManager retrievePairedPeersWithOptions:] <private>
PerfPowerServices: (CoreBluetooth) [com.apple.bluetooth:CoreBluetooth] Sending synchronous XPC message <private>: <private>
bluetoothd: [com.apple.bluetooth:Server.XPC] Received XPC message "CBMsgIdRetrievePairedPeersWithOptions" from session "com.apple.PerfPowerServices-classic-164-17"
bluetoothd: (CoreFoundation) [com.apple.defaults:User Defaults] looked up value <private> for key [SOME MAC] in CFPrefsPlistSource<0x7fb00020d020> (Domain: com.apple.MobileBluetooth.devices, User: kCFPreferencesCurrentUser, ByHost: No, Container: /Library/Bluetooth, Contents Need Refresh: No) via CFPrefsSearchListSource<0x7fb000115150> (Domain: com.apple.MobileBluetooth.devices, Container: /Library/Bluetooth)
bluetoothd: [com.apple.bluetooth:Server.Core] TagSet's class is not an NSArray, returning error for  69422B50
bluetoothd: [com.apple.bluetooth:Server.Security] 69422B50 hasTS: 0, res: 1
bluetoothd: (CoreFoundation) [com.apple.defaults:User Defaults] looked up value <private> for key [SOME MAC] in CFPrefsPlistSource<0x7fb00020d020> (Domain: com.apple.MobileBluetooth.devices, User: kCFPreferencesCurrentUser, ByHost: No, Container: /Library/Bluetooth, Contents Need Refresh: No) via CFPrefsSearchListSource<0x7fb000115150> (Domain: com.apple.MobileBluetooth.devices, Container: /Library/Bluetooth)
bluetoothd: [com.apple.bluetooth:Server.Core] TagSet's class is not an NSArray, returning error for  683AA17B
…
bluetoothd: [com.apple.bluetooth:Server.Security] 9C6B4312 hasTS: 0, res: 1
bluetoothd: [com.apple.bluetooth:Server.LE] Already tracking address "<private>" as device "[SOME MAC]"
bluetoothd: [com.apple.bluetooth:Server.Core] Get SDP record data from SDP attributes for device 69422B50
bluetoothd: [com.apple.bluetooth:Server.Core] SDP record cache size 1200 with 12 services
bluetoothd: [com.apple.bluetooth:Server.Core] Returning sdp record NSData: <private>
bluetoothd: [com.apple.bluetooth:Server.XPC] bluetoothd sending sdp data: <private>
bluetoothd: [com.apple.bluetooth:Server.LE] Already tracking address "<private>" as device "[SOME MAC]"
bluetoothd: [com.apple.bluetooth:Server.Core] Get SDP record data from SDP attributes for device 683AA17B
bluetoothd: [com.apple.bluetooth:Server.Core] sdp attributes is empty

@fsonntag
Copy link

fsonntag commented Jan 4, 2022

@toy Any updates on that? :)

@toy
Copy link
Owner

toy commented Jan 4, 2022

@fsonntag Sadly no, checking on the surface showed that methods are broken and I didn't yet have time to create environment to investigate deeply. For now I can suggest checking if blueutil --paired or blueutil --connected can be of help.

@friedrichweise
Copy link
Contributor Author

friedrichweise commented Jan 5, 2022

blueutil --paired and blueutil --connected work like a charm…

@fsonntag are you able to reproduce the bug? What device are you using? My speculation is that this bug only affects Intel based devices that run macOS 12.

@fsonntag
Copy link

@friedrichweise
Sorry for the late reply, somehow missed this :/

Anyway, both commands run without an issue, no error output.

@wwwjfy
Copy link

wwwjfy commented Jan 30, 2022

[IOBluetoothDevice recentDevices] returns empty. I made the following change to make connecting by name work, in function get_device. could be a macOS bug (Intel only? I'm using Mac mini 2018 and MBP 2019). #58 #62 should be of the same cause.

diff --git blueutil.m blueutil.m
index 47aa91d..b5225d5 100644
--- blueutil.m
+++ blueutil.m
@@ -277,7 +277,7 @@ IOBluetoothDevice *get_device(char *id) {
       exit(EXIT_FAILURE);
     }
   } else {
-    NSArray *recentDevices = [IOBluetoothDevice recentDevices:0];
+    NSArray *recentDevices = [IOBluetoothDevice pairedDevices];

     if (!recentDevices) {
       eprintf("No recent devices to search for: %s\n", id);

localauthor added a commit to localauthor/launchbar-bluetooth-devices that referenced this issue Apr 1, 2022
"blueutil --recent" and "blueutil --disconnect" don't work in Monterey
(among others)

Until these are fixed, this patch replaces them with "--paired" and
"--wait-disconnect" respectively per:
toy/blueutil#63
toy/blueutil#58
@toy toy mentioned this issue Mar 4, 2023
azuwis added a commit to azuwis/blueutil that referenced this issue Mar 26, 2024
IOBluetoothDevice.recentDevices return empty list in macOS Monterey and
later, use IOBluetoothDevice.pairedDevices instead, to make

  --info "BY NAME"
  --connect "BY NAME"
  --disconnect "BY NAME"
  ...

work again.

Fix toy#58 toy#62 toy#63
@toy toy closed this as completed in 30fbc48 Apr 10, 2024
@toy
Copy link
Owner

toy commented Apr 10, 2024

I can only document that functionality is broken, concerning fixing finding devices by name, see #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants