Skip to content

Instantly share code, notes, and snippets.

@timgws
Last active November 1, 2018 17:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timgws/fc63aeca6a248bbb25ff to your computer and use it in GitHub Desktop.
Save timgws/fc63aeca6a248bbb25ff to your computer and use it in GitHub Desktop.
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
Copy link

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