Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottshane/f510eb7734fbf95672cad9d233a9526c to your computer and use it in GitHub Desktop.
Save scottshane/f510eb7734fbf95672cad9d233a9526c 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment