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

15,435

Solution 1

I'm going to use blueutil.

-- gadgetmo

Solution 2

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.

For the former method, use launchctl to tell launchd to unload the daemon and set its disabled flag:

# 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):

# 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:

# launchctl start com.apple.blued
Share:
15,435
gadgetmo
Author by

gadgetmo

Updated on June 04, 2022

Comments

  • gadgetmo
    gadgetmo about 2 years

    How do I turn off bluetooth via terminal/shell/automator/applescript on a Mac? It should be pretty easy.

    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.

    • A. Wilcox
      A. Wilcox over 12 years
      Should be moved to Super User, this is not a programming problem. That said, see blueutil. It should do exactly what you want.
  • Simone Manganelli
    Simone Manganelli almost 12 years
    Dunno if this answer ever worked, but there are multiple things wrong with it. First of all, it should be "-bool NO" or "-bool YES". "-BOOL" (uppercase) and "1" or "0" are all invalid arguments. Second, you need to use sudo: sudo launchctl start com.apple.blued. Better to use explicit path: sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist and sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist . Finally, that pref doesn't actually seem to set whether Bluetooth is on or not. At least not on Lion.
  • Ivan Vučica
    Ivan Vučica about 11 years
    @SimoneManganelli Consider posting your information as a full-fledged answer, or suggest an edit to Spencer's answer.