Is there a command-line interface to list all Bluetooth devices in range on mac?
<p>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.</p>
<p>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.  <strong>I would be happy with a macOS Swift code example, AppleScript example, bash example, or pointers to good docs as answers.</strong></p>
<p>I've looked at these options so far:</p>
<ul>
<li><code>blued</code>: 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 hostnames</li>
<li><code>blueutil</code> (<code>brew install blueutil</code>): only prints power state, not device names</li>
<li><code>bluetoothaudiod</code>: no usable interface</li>
<li>This Objective-C code <a href="https://stackoverflow.com/questions/4271014/create-a-terminal-based-bluetooth-monitor-in-xcode">Create a Terminal-Based Bluetooth Monitor in XCode?</a>: I get several errors when compiling so it's hard to test it</li>
<li>Using AppleScript to read it out the <code>Bluetooth Explorer.app</code> GUI</li>
<li>Using <code>dtrace</code> to see how <code>Bluetooth Explorer.app</code> computes the list: difficult last resort</li>
<li>The <a href="https://github.com/revned/proximity" rel="nofollow noreferrer">Proximity</a> App from <a href="http://hints.macworld.com/article.php?story=20091221173111783" rel="nofollow noreferrer">this forum post</a>: Doesn't have a command line interface, so I cant query it remotely.  I can write a script that stores the state in a file to read later, but it only works for one device at a time.</li>
</ul>
<p>Edit 2017/01: Found this SO answer with details on finding nearby devices in Swift:<br />
<a href="https://stackoverflow.com/questions/24321126/list-devices-that-are-in-range-of-bluetooth-device-in-swift">List devices that are in range of Bluetooth device in Swift</a></p>
<p>Edit 2017/10: Found an updated SO answer for Swift 3 &amp; 4.0: <a href="https://stackoverflow.com/questions/40636726/nearby-bluetooth-devices-using-swift-3-0/41941490#41941490">Nearby Bluetooth devices using Swift 3.0</a></p>