-
-
Save tyilo/c92684d277acb62272b5 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# Install sleepwatcher | |
cd /tmp | |
curl -O http://www.bernhard-baehr.de/sleepwatcher_2.2.tgz | |
tar -zxvf sleepwatcher_2.2.tgz | |
cd sleepwatcher_2.2 | |
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8 | |
sudo cp sleepwatcher /usr/local/sbin | |
sudo cp sleepwatcher.8 /usr/local/share/man/man8 | |
sudo cp config/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents | |
sudo cp config/rc.* /etc | |
cd .. | |
rm -r sleepwatcher_2.2* | |
# Add bluetooth script to /etc/rc.wakeup (the script requires root) | |
sudo tee -a /etc/rc.wakeup <<EOF | |
kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport | |
kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport | |
EOF | |
# Load the agent to start sleepwatcher | |
sudo launchctl load /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist |
@gh91745, you have to add it to your launchd startup files. These instructions are given when you install sleepwatcher via Homebrew:
To have launchd start sleepwatcher at login:
ln -sfv /usr/local/opt/sleepwatcher/*.plist ~/Library/LaunchAgents
This will load sleepwatcher automatically when you login the first time. To load it immediately, run the following command (also provided during the Homebrew install):
launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist
Thanks a lot!!
I'm on macOS Sierra and using homebrew. I tried following the steps here and a few other locations, but ran into isses with the plist files being slightly different and not loading the correct /etc/rc.wakeup
file. I modified the script above and got these commands that got things working reliably for me. Hope it helps someone else.
brew install sleepwatcher
sudo touch /etc/rc.sleep
sudo tee -a /etc/rc.wakeup <<EOF
#!/bin/sh
# Sleepwatcher script to get bluetooth working after the mac wakes up
# Got this approach from https://gist.github.com/Tyilo/c92684d277acb62272b5
kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
EOF
sudo chmod +x /etc/rc.wakeup
brew services start sleepwatcher
sudo tee -a /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-custom.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>de.bernhard-baehr.sleepwatcher</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/sleepwatcher</string>
<string>-V</string>
<string>-s /etc/rc.sleep</string>
<string>-w /etc/rc.wakeup</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
sudo launchctl load /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-custom.plist
Looks like the kextunload
commands don't actually work anymore on High Sierra. However, there's a 3rd party command line tool for doing the same thing and it works: https://github.com/toy/blueutil – you can tweak the scripts mentioned here to use blueutil
instead, or there's even a full-blown solution (very similar to what we have seen on this page already): https://gist.github.com/ralph-hm/a65840c4f5e439b90170d735a89a863f
Thank you very much. A simple cost-effective solution to a major Bluetooth failing on Mac Yosemite.