Forked from timgws/install-sleepwatcher-bluetooth-fix.sh
Created
October 24, 2017 19:57
-
-
Save scottshane/f510eb7734fbf95672cad9d233a9526c to your computer and use it in GitHub Desktop.
Install sleepwatcher to restart bluetooth & friends
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/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