I want to list all in-range Bluetooth devices, ideally with hostnames, but MAC addresses would be sufficient. I need a command that performs an active scan so I can poll to see if my device is nearby, not one that lists previously paired devices.
My use-case is detecting whether my Bluetooth headphones or iPhone are in range of my Mac, to trigger security setting changes (e.g. sudo timeout). I've done a fair bit of Googling, and the only things I seem to be able to find are iOS swift code examples. I would be happy with a macOS Swift code example, AppleScript example, bash example, or pointers to good docs.
I've looked at these options so far:
blued
: prints a list of mac addresses but they don't seem to change when devices go in or out of range or connect, and they aren't matched up to hostnamesblueutil
(brew install blueutil
): only prints power state, not device namesbluetoothaudiod
: no usable interfaceBluetooth Explorer.app
GUIdtrace
to see how Bluetooth Explorer.app
computes the list: difficult last resortEdit 2017/01: Found this SO answer with details on finding nearby devices in Swift:
List devices that are in range of Bluetooth device in Swift
Edit 2017/10: Found an updated SO answer for Swift 3 & 4.0: Nearby Bluetooth devices using Swift 3.0
In order to check Bluetooth logs open the Console. app e.g. by pressing cmd + space , then typing "Console" and hitting Enter . Inside the Console. app you can filter messages just to Bluetooth related by typing "bluetooth" inside Search field.
The official Bluetooth specifications say seven is the maximum number of Bluetooth devices that can be connected to your Mac at once. However, three to four devices is a practical limit, depending on the types of devices used. Some devices require more Bluetooth data, so they're more demanding than other devices.
In Terminal, the command :
system_profiler SPBluetoothDataType
gives you all the details about Bluetooth, including devices paired, with their names, MAC address. Result is unfortunately a bit too much, but with sed or grep command, you should extract what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With