简体   繁体   English

终端/外壳/自动/ applescript命令在Mac上关闭蓝牙

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

How do I turn off bluetooth via terminal / shell / automator / applescript on a Mac? 如何在Mac上通过terminal / shell / automator / applescript关闭bluetooth It should be pretty easy. 应该很容易。

BTW, I know you can get applescript to press the bluetooth menu and then press turn bluetooth off . 顺便说一句,我知道您可以让applescript按下bluetooth菜单,然后按turn bluetooth off I don't want this if possible. 如果可能的话,我不要这个。

I'm going to use blueutil . 我将使用blueutil

-- gadgetmo -gadgetmo

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卸载Bluetooth守护程序,而不再按需启动它,或者您可以通过编程方式切换它的首选项并停止服务器。

For the former method, use launchctl to tell launchd to unload the daemon and set its disabled flag: 对于前一种方法,请使用launchctl告诉launchd卸载守护程序并设置其disable标志:

# 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: 然后启动脚踢使其再次变blued

# launchctl start com.apple.blued

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM