Mac自动连接蓝牙设备---小爱音箱

Mac自动连接蓝牙设备---小爱音箱

视频教程地址:https://www.bilibili.com/video/BV1ec411E7EA

因为清理文件,不小时删除了原来的蓝牙“自动操作”,这里再记录一次。

原理很简单,开机启动“自动操作”,来执行blueutil命令开启蓝牙并连接设备。简述

Mac对蓝牙的“自动操作”,需要依赖blueutil工具。

blueutil是一个开源命令行bash实用程序,用于控制OSX中的Bluetooth I / O

blueutil命令

blueutil –help 查看帮助信息


    -p, --power               output power state as 1 or 0
    -p, --power STATE         set power state
    -d, --discoverable        output discoverable state as 1 or 0
    -d, --discoverable STATE  set discoverable state

        --favourites, --favorites
                              list favourite devices
        --inquiry [T]         inquiry devices in range, 10 seconds duration by default excluding time for name updates
        --paired              list paired devices
        --recent [N]          list recently used devices, 10 by default, 0 to list all
        --connected           list connected devices

        --info ID             show information about device
        --is-connected ID     connected state of device as 1 or 0
        --connect ID          create a connection to device
        --disconnect ID       close the connection to device
        --pair ID [PIN]       pair with device, optional PIN of up to 16 characters will be used instead of interactive input if requested in specific pair mode
        --unpair ID           EXPERIMENTAL unpair the device
        --add-favourite ID, --add-favorite ID
                              add to favourites
        --remove-favourite ID, --remove-favorite ID
                              remove from favourites

        --format FORMAT       change output format of info and all listing commands

        --wait-connect ID [TIMEOUT]
                              EXPERIMENTAL wait for device to connect
        --wait-disconnect ID [TIMEOUT]
                              EXPERIMENTAL wait for device to disconnect
        --wait-rssi ID OP VALUE [PERIOD [TIMEOUT]]
                              EXPERIMENTAL wait for device RSSI value which is 0 for golden range, -129 if it cannot be read (e.g. device is disconnected)

    -h, --help                this help
    -v, --version             show version

这里只用2个参数即可:

-p(power)【蓝牙电源控制,1为打开、0为关闭】

#打印当前蓝牙
blueutil
#打开蓝牙
blueutil -p 1
#关闭蓝牙
blueutil -p 0

–connect ID 【连接蓝牙设备ID】

#如连接蓝牙设备为11-22-33-44-55-66
blueutil --connect 11-22-33-44-55-66

“自动操作”脚本

看懂上面两个命令,合起来就是“自动操作”的脚本

blueutil -p 1
blueutil --connect 【你蓝牙设备ID】

一,安装brew

查看是否安装brew,若已经安装可以跳过当前步骤

brew -v
https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-30.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

若未安装,执行命令进行安装,安装周期与你网速成正比。

brew官网:https://brew.sh/

第三方源很多不做推荐,自行百度

二,安装blueutil

查看是否安装blueutil

blueutil
https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-38.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

安装命令:

brew install blueutil

三,查看blueutil安装路径

记录查询结果,因为”自动操作”需要使用绝对路径)

brew list blueutil
https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-31.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

四,获取蓝牙地址

获取要连接的蓝牙设备ID(MAC地址),

鼠标操作查询:关于本机—>系统报告—>蓝牙—>你要自动连接的蓝牙设备

https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-34.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

使用命令查询:

system_profiler SPBluetoothDataType

五,创建”自动操作”

打开”启动台”—>打开”自动操作”—>文稿类型”应用程序”—>搜索”shell”—>将”运行shell”拖到右侧

https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-32.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

粘贴执行命令,此处

【上一步查询到的blueutil绝对路径】 -p 1
【上一步查询到的blueutil绝对路径】 --connect 【你蓝牙设备ID】

起个名字,保存到《应用程序》目录,防止不小心删除了

https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-33.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

六,添加开机启动

打开”系统偏好”—>”用户与群组”—>”用户”—>”登录项”—>”添加”—>刚刚创建的”自动操作”—>ok

https://qnimg.ffing.cn/wp-content/uploads/2023/03/image-35.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

good good study, day day up!

发表评论

textsms
account_circle
email

Mac自动连接蓝牙设备---小爱音箱
视频教程地址:https://www.bilibili.com/video/BV1ec411E7EA 因为清理文件,不小时删除了原来的蓝牙“自动操作”,这里再记录一次。 原理很简单,开机启动“自动操作”,来执行blueuti…
扫描二维码继续阅读
2023-03-12