-
-
Save franciscbalint/d008370c49a37f7051b1afef8567fefd to your computer and use it in GitHub Desktop.
Restart Bluetooth Daemon on Mac OS X/macOS Sierra without restarting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
(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
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