toy / blueutil

CLI for bluetooth on OSX: power, discoverable state, list, inquire devices, connect, info, …
https://github.com/toy/blueutil
Other
972 stars 52 forks source link

Retrieve custom names of devices in addition to factory names #40

Open ericpedia opened 3 years ago

ericpedia commented 3 years ago

When pulling --info and --paired lists, the name property contains the default factory name of each device. Is there a way to pull the devices' custom names as well, if they exist?

I'm referring to the MacOS feature of renaming bluetooth devices: In the System Preferences » Bluetooth device list, you can right-click any connected device and rename it. Now the custom name will be displayed in the menubar's Bluetooth dropdown and the Bluetooth preferences, and will persist for all users until the device is removed/forgotten.

This is handy for changing default factory names to something easier to identify and to distinguish between multiple devices whose factory names are hard to tell apart (e.g., Kitchen Speaker and Bedroom Speaker instead of XX-Company-01 and XX-Company-02).

It would be useful to have access to these names when running the --info and --paired commands.

image

toy commented 3 years ago

Thank you for bringing it up! I didn't know that the method to get the device name did not always return the custom name.

After some reading and experimenting, I see that changing names works differently depending on device, some get it stored on device itself and renaming right away shows up in blueutil, for others custom name is stored locally and is not returned by method used in the tool.

I didn't find any API to get the custom name, but checked /Library/Preferences/com.apple.Bluetooth.plist and it seems that some devices under DeviceCache have displayName set, so fetching custom names from there can be added to the tool.