Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install sleepwatcher to restart bluetooth & friends
#!/bin/sh
brew install sleepwatcher
# https://gist.github.com/jagtesh/de81fa1c6b45fad0ff8e
sudo cp /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents/
sudo cp /usr/local/Cellar/sleepwatcher/2.2/etc/sleepwatcher/rc.* /etc/
# Add bluetooth script to /etc/rc.wakeup (the script requires root)
sudo tee -a /etc/rc.wakeup <<EOF
##
## Restart blued & load/unload bluetooth driver.
##
function msg() {
foo=\$2
what="\$(tr '[:lower:]' '[:upper:]' <<< \${foo:0:1})\${foo:1}"
echo ">> \${what}ing \$1...";
}
function __blued() {
msg "blued" "\$1";
sudo launchctl \$1 /System/Library/LaunchDaemons/com.apple.blued.plist
}
function __driver() {
msg "bluetooth driver" "\$1";
sudo kext\$1 -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
}
__blued "unload"
__driver "unload"
sleep 2;
__driver "load";
__blued "load"
EOF
# Load the agent to start sleepwatcher
sudo launchctl load /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist
@inspiredearth

This comment has been minimized.

Copy link

@inspiredearth inspiredearth commented Jul 16, 2015

Thanks for this. Very helpful for my MBP Bluetooth woes.

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