How to restart Bluetooth service from command line
On High Sierra, none of the command line options worked for me. I was able to plug in a wired USB mouse and use the Shift + Option with Debug/Rest solution.
I tried the blueutil solution on my High Sierra, and it worked like a charm. I regularly have Bluetooth on my 2015 MBPR with an Apple Magic Mouse hose up, and have to restart. Yeah, I could open the lid and use the track pad, but it's on the other side of the wall from my desk space.
You can install blueutil using Homebrew:
brew install blueutil
Or you can compile and install it by hand using:
cd ~/tmp/
git clone https://github.com/toy/blueutil.git
cd blueutil
make
make test
cp blueutil ~/bin/
Now run:
blueutil -p 0 && sleep 1 && blueutil -p 1
On El Capitan, it's kind of tricky because it doesn't allow you to unload system services. However, a brute-force method is:sudo pkill blued
'blued' is the OS X bluetooth daemon, and it will automatically restart when terminated (at least when I tested it on my El Capitan machine). Other related daemons are: com.apple.bluetoothReporter, com.apple.IOBluetoothUSBDFU, and com.apple.bluetoothaudiod (you can look at the daemons running using sudo launchctl list
)
You can also try:
sudo launchctl stop com.apple.blued
sudo launchctl start com.apple.blued
If you have an older OS X version, it's cleaner:
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
or
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
One thing to mention is the daemon name blued (at least until macOS 10.11 El Capitan), has been changed to bluetoothd.
So based on the version of the macOS, you need to change the daemon name in the below command(s).
Another thing to note is that, unload then load the daemon's plist(instead of stop then start or sending HUP signal) may not work due to the SIP(System Integrity Protection) introduced in El Capitan. But it should work when you disabled the SIP or on macOS before El Capitan.
$ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
Even in the SIP environment(after El Capitan) you can simply launchctl stop then launchctl start the daemon.
$ sudo launchctl stop com.apple.bluetoothd # or blued based on macOS version
$ sudo launchctl start com.apple.bluetoothd
In case you just want the status(on|off) of bluetooth to be changed, not wanting the daemon to actually restart, you can do the following,
# Let bluetooth be on
$ sudo defaults write
/Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 1
# let bluetooth be off
$ sudo defaults write
/Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 0
# Then reload the daemon
$ sudo killall -HUP bluetoothd # or blued based on macOS version
# On a macOS system which has proctools installed, you can replace `killall` to `pkill`
Blueutil is cool stuff, but it is using some private APIs of IOBluetooth.framework, so it may not work on the future version of macOS.
sudo pkill bluetoothd
Works for me on macOS High Sierra My Logitech mx anywhere does not work after sleep sometimes. As I read its not because of mouse, it's a macOS Smart Bluetooth bug. But my Apple keyboard always works, never got this issue. Sometimes I wake up my computer, the Apple keyboard is working but the Logitech mouse is not working. So without the mouse I cannot restart Bluetooth from the system (I could close but my keyboard also go away, so cannot restart again) I started to use this command from terminal, it stops the service but when the service stops it automatically restarts it self. And my mouse starts working within a second!
For my Macbook Pro 2017 with macOS High Sierra 10.13.6, I restart bluetooth using the following bash script:
#!/bin/bash
sudo launchctl stop com.apple.bluetoothd
sudo launchctl start com.apple.bluetoothd