如何查找某个蓝牙设备是否已连接?

时间:2018-01-18 18:18:30

标签: bluetooth applescript

我想使用applescript定期(每秒)检查一下是否连接了特定的蓝牙设备,如果是,则闪烁快速通知。为了构建它,我需要一个弹出窗口,当我的Airpods连接时,因为有时当我把它们拉出来时,连接到我的电脑,有时连接到我的iPhone。

除了蓝牙检查部分外,我已经弄明白了。我已经将此作为起点,但无法使其发挥作用。任何帮助将不胜感激。

#small_wrap > div{
    width: 24%;
    /*padding-bottom : 23.3%;*/
    margin: 0%;
    margin-bottom:0;
}

2 个答案:

答案 0 :(得分:2)

您错过了e

set myString to do shell script "system_profiler SPBluetoothDataType"
                                                                   ^

答案 1 :(得分:0)

我正在做类似的事情。这似乎在macOS Mojave上运行良好:

use framework "IOBluetooth"
use scripting additions -- https://stackoverflow.com/a/52806598/6962

on isDeviceConnected(substring)
    repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
        if device's isConnected and (device's nameOrAddress as string) contains substring then return true
    end repeat

    return false
end isDeviceConnected

-- Usage example:
isDeviceConnected("AirPods")

我将其与这样的启动代理结合:https://gist.github.com/henrik/3d4c622a5567cdf2bf461352f48ad4dd