Skip to content

Instantly share code, notes, and snippets.

@franciscbalint
Forked from nicolasembleton/restart_bluetooth.sh
Last active July 19, 2018 12:00
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save franciscbalint/d008370c49a37f7051b1afef8567fefd to your computer and use it in GitHub Desktop.
Save franciscbalint/d008370c49a37f7051b1afef8567fefd to your computer and use it in GitHub Desktop.
Restart Bluetooth Daemon on Mac OS X/macOS Sierra without restarting
#!/bin/bash
# To run this script you need to give execute permission.
# $chmod +x restart_bluetooth.sh;
# If you want only to restart:
# $ ./restart_bluetooth.sh;
# If you want to turn bluetooth on;
# $ ./restart_bluetooth.sh 1;
# If you want to turn bluetooth off;
# $ ./restart_bluetooth.sh 0;
#Default
output="Bluetooth restarted";
if [ $# -eq 1 ]; then
if [ $1 -eq "1" ]; then
sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 1
output="Bluetooth is on";
elif [ $1 -eq "0" ]; then
sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 0
output="Bluetooth is off";
fi;
fi;
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
echo $output;
@franciscbalint
Copy link
Author

I added this file to
/usr/local
And also put this line
alias bluesh="/usr/local/restart_bluetooth.sh"
in
$sudo vim ~/.bashrc
after I finish, I update the new changes with
$source ~/.bash_profile
so I can run this from terminal to turn it on/off
$bluesh 1

@mirko77
Copy link

mirko77 commented Mar 9, 2018

(kernel) Can't remove kext com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport; services failed to terminate - 0xdc008018. Failed to unload com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport - (libkern/kext) kext is in use or retained (cannot unload). Bluetooth restarted

OS X 10.3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment