通过终端与蓝牙设备配对


12

我正在尝试从命令行连接并配对蓝牙设备。我可以使用标准过程通过GUI进行操作,但是我希望实现整个过程的自动化。

我正在寻找可以在Shell脚本中执行以连接到蓝牙设备的命令。就像Linux具有“ hcitool”,“ pand”命令一样,我试图为macOS寻找等效命令。

我该怎么做?

Answers:


2

这似乎有些“ hacky”,但是您可以通过使用模拟连接所需的GUI交互的oascript来做到这一点:https ://stackoverflow.com/a/23018886/5269642

不幸的是,我找不到真正的蓝牙API,到目前为止,oascript方法是我能找到/想到的最好的方法。


1

blueutil(可通过HomeBrew获得)就是答案。我只是按照此博客文章中的指南使用它。

就我而言,我有一台没有macOS Catalina的iMac,没有配对触控板。我被困在“发送Apple Crash Analytics?” 屏幕,没有键盘控件。使用SSH,我连接到计算机,并使用以下命令进行配对,然后在不访问GUI的情况下连接了触控板。(首先,我必须将触控板转到可发现模式。Apple指针设备的默认PIN是0000。)

% blueutil --inquiry
address: d0-a6-xx-xx-xx-xx, not connected, not favourite, not paired, name: "-", recent access date: -
% blueutil --pair d0-a6-xx-xx-xx-xx
Type pin code (up to 16 characters) for "Cheshire, Josh’s Trackpad" (d0-a6-xx-xx-xx-xx) and press Enter: 0000
% blueutil --connect d0-a6-xx-xx-xx-xx

到那时,触控板开始工作了。


0

工具blueutil使用IOBluetooth框架中的私有API与蓝牙设备进行交互。您可以使用以下方法列出最近的设备:

blueutil --recent

并使用以下命令连接到特定设备:

blueutil --connect $device_adress
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.