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

发布于 2024-12-06 01:59:50 字数 63 浏览 3 评论 0原文

有没有办法以编程方式在 OS X 中设置蓝牙可发现模式(真/假)?

而不是要求用户打开/关闭它?

Is there a way to set the Bluetooth Discoverable mode (true/false) in OS X programmatically?

Instead of asking the user to turn it on/off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2024-12-13 01:59:50

您可以使用 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();

You can use the OS X private API IOBluetoothPreferenceSetDiscoverableState.

// Declaration of private API
void IOBluetoothPreferenceSetDiscoverableState(int discoverable);
int IOBluetoothPreferenceGetDiscoverableState();

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

You might also find useful the APIs for turning on and off bluetooth:

void IOBluetoothPreferenceSetControllerPowerState(int powered);
int IOBluetoothPreferenceGetControllerPowerState();
朕就是辣么酷 2024-12-13 01:59:50

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

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

结束告诉

这个苹果脚本将打开/关闭蓝牙可见性。希望这会有所帮助。

tell application "System Preferences"

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

end tell

This apple script will Switch On/Off Bluetooth visibility.Hope this will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文