【问题标题】:terminal/shell/automator/applescript command to turn off bluetooth on mac终端/shell/automator/applescript 命令在 Mac 上关闭蓝牙
【发布时间】:2012-01-31 18:17:57
【问题描述】:

如何在 Mac 上通过 terminal/shell/automator/applescript 关闭 bluetooth?这应该很容易。

顺便说一句,我知道你可以让 applescript 按bluetooth 菜单,然后按turn bluetooth off。如果可能,我不想要这个。

【问题讨论】:

  • 应该移到超级用户,这不是编程问题。也就是说,请参阅blueutil。它应该完全符合您的要求。

标签: macos shell terminal applescript automator


【解决方案1】:

我将使用blueutil。

-- gadgetmo

【讨论】:

    【解决方案2】:

    有两种方法可以解决。您可以告诉launchd 卸载蓝牙守护程序并且不再按需启动它,或者您可以通过编程方式切换它的首选项并停止服务器。

    对于前一种方法,使用launchctl 告诉launchd 卸载守护程序并设置其禁用标志:

    # launchctl unload -w /System/Library/LaunchDaemons/com.apple.blued.plist
    

    如果你想稍后恢复它,这就足够了:

    # launchctl load -wF /System/Library/LaunchDaemons/com.apple.blued.plist
    

    应该这样做。现在对于后一种方法,首先更新首选项文件(从 UI 切换时会发生同样的事情):

    # defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState -BOOL 0
    

    然后,你可以粗暴地杀死服务器:

    # killall blued
    

    稍后,您可以通过重置位来恢复首选项:

    # defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState -BOOL 1
    

    然后kick launchd 让它再次启动blued:

    # launchctl start com.apple.blued
    

    【讨论】:

    • 不知道这个答案是否有效,但它有很多问题。首先,它应该是“-bool NO”或“-bool YES”。 “-BOOL”(大写)和“1”或“0”都是无效参数。其次,需要使用 sudo:sudo launchctl start com.apple.blued。最好使用显式路径:sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist 和 sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist。最后,该首选项实际上似乎并没有设置蓝牙是否打开。至少不是在 Lion 上。
    • @SimoneManganelli 考虑将您的信息发布为完整的答案,或建议对 Spencer 的答案进行修改。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    相关资源
    最近更新 更多