screen shot 2019-02-16 at 11 30 23 am

BluetoothConnector

简单的 macOS 命令行工具,用于连接/断开蓝牙设备。我制作它是为了方便连接我的 BeatsX 耳机(我以为 W1 芯片能让从 iPhone 切换到 Mac 变得无缝,但显然我们还没达到那种程度)。可能已经有程序可以做到这一点,但我没有找到。

您可以在这里下载编译好的版本: https://github.com/lapfelix/BluetoothConnector/releases

如果您在运行编译好的二进制文件时遇到问题(permission denied 错误),请尝试在终端中运行此命令:chmod +x /path/to/BluetoothConnector

安装

Homebrew

brew install bluetoothconnector

Mint

mint install lapfelix/BluetoothConnector

手动

swift package update
swift build -c release
mv .build/release/BluetoothConnector /usr/local/bin/BluetoothConnector

用法

运行

00-00-00-00-00-00 替换为您的设备的 MAC 地址。您可以通过按住 Alt 键并点击蓝牙菜单图标来获取它,或者直接运行不带任何参数的 BluetoothConnector

切换连接状态(连接/断开连接)并接收通知
BluetoothConnector 00-00-00-00-00-00 --notify
连接并接收通知
BluetoothConnector --connect 00-00-00-00-00-00 --notify
BluetoothConnector -c 00-00-00-00-00-00 --notify
断开连接
BluetoothConnector --disconnect 00-00-00-00-00-00
BluetoothConnector -d 00-00-00-00-00-00
通知中心

screen shot 2019-01-27 at 4 51 16 pm

您可以让 BluetoothConnector 发送通知,告知您它执行的操作(连接或断开连接),操作是否成功,或者在出现问题时获取错误描述。

BluetoothConnector 00-00-00-00-00-00 --notify

为了减少通知中心的消息干扰,我建议在“通知”系统偏好设置中关闭“在通知中心显示”Script Editor 应用的通知。

screen shot 2019-01-27 at 4 51 16 pm

使用 Automator 绑定快捷键(我就是这样用的)

我包含了一个 Automator 工作流程服务,它从 /usr/local/bin 调用 BluetoothConnector,以便更轻松地使用键盘快捷流程运行 BluetoothConnector(我就是这样用的)。

然后打开 Automator 工作流程,您应该会收到安装提示(不要忘记更改 MAC 地址)。要将快捷键绑定到 Automator 服务,请启动“系统偏好设置”并转到 键盘 > 快捷键 > 服务,找到您的服务并为其添加快捷键。