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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:44:24  来源:igfitidea点击:

terminal/shell/automator/applescript command to turn off bluetooth on mac

macosshellterminalapplescriptautomator

提问by gadgetmo

How do I turn off bluetoothvia terminal/shell/automator/applescripton a Mac? It should be pretty easy.

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

BTW, I know you can get applescript to press the bluetoothmenu and then press turn bluetooth off. I don't want this if possible.

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

回答by gadgetmo

I'm going to use blueutil.

我将使用blueutil

-- gadgetmo

-- 小工具

回答by Spencer

There are two ways to go about it. You can tell launchdto 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 launchctlto tell launchdto unload the daemon and set its disabled flag:

对于前一种方法,使用launchctlto 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 bluedagain:

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

# launchctl start com.apple.blued