macos 在mac上关闭蓝牙的终端/shell/automator/applescript命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8699896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
terminal/shell/automator/applescript command to turn off bluetooth on mac
提问by gadgetmo
How do I turn off bluetooth
via terminal
/shell
/automator
/applescript
on a Mac? It should be pretty easy.
如何关闭bluetooth
通过terminal
/ shell
/ automator
/ applescript
Mac上?这应该很容易。
BTW, I know you can get applescript to press the bluetooth
menu and then press turn bluetooth off
. I don't want this if possible.
顺便说一句,我知道你可以让 applescript 按下bluetooth
菜单,然后按下turn bluetooth off
。如果可能的话,我不想要这个。
回答by Spencer
There are two ways to go about it. You can tell launchd
to unload the Bluetooth daemon and no longer start it on demand, or you can programmatically toggle the preference for it and stop the server.
有两种方法可以解决这个问题。您可以告诉launchd
卸载蓝牙守护程序,不再按需启动它,或者您可以以编程方式切换它的首选项并停止服务器。
For the former method, use launchctl
to tell launchd
to unload the daemon and set its disabled flag:
对于前一种方法,使用launchctl
to telllaunchd
卸载守护进程并设置其禁用标志:
# launchctl unload -w /System/Library/LaunchDaemons/com.apple.blued.plist
If you want to restore it later, this should suffice:
如果您想稍后恢复它,这应该就足够了:
# launchctl load -wF /System/Library/LaunchDaemons/com.apple.blued.plist
That should do it. Now for the latter method, first update the preference file (same thing that would happen when toggling from the UI):
那应该这样做。现在对于后一种方法,首先更新首选项文件(从 UI 切换时会发生同样的事情):
# defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState -BOOL 0
Then, you can just rudely kill off the server:
然后,您可以粗鲁地关闭服务器:
# killall blued
Later, you can restore the preference by resetting the bit:
稍后,您可以通过重置位来恢复首选项:
# defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState -BOOL 1
Then kick launchd to have it fire up blued
again:
然后踢launchd让它blued
再次启动:
# launchctl start com.apple.blued