如何在OS X中以编程方式设置蓝牙可发现模式

3
有没有一种方法可以在OS X中以编程方式设置蓝牙可发现模式(true/false)?而不是要求用户打开/关闭它?
2个回答

6
您可以使用OS X私有API IOBluetoothPreferenceSetDiscoverableState来设置蓝牙可发现状态。
// Declaration of private API
void IOBluetoothPreferenceSetDiscoverableState(int discoverable);
int IOBluetoothPreferenceGetDiscoverableState();

// Usage
// Turn on Discoverability
IOBluetoothPreferenceSetDiscoverableState(1);
// Get current discoverable state
IOBluetoothPreferenceGetDiscoverableState()

您可能会发现打开和关闭蓝牙的API也很有用:

void IOBluetoothPreferenceSetControllerPowerState(int powered);
int IOBluetoothPreferenceGetControllerPowerState();

1

告诉应用程序“系统偏好设置”

set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events"
    tell process "System Preferences"
        set isOnCheckbox to checkbox "On" of window "Bluetooth"
        if value of isOnCheckbox is 0 then
            click isOnCheckbox
        end if
    end tell
end tell
quit

结束告诉

这个苹果脚本将开启/关闭蓝牙可见性。希望这能帮到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接