Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Install sleepwatcher
cd /tmp
curl -O
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
kextload -b
# Load the agent to start sleepwatcher
sudo launchctl load /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist
Copy link

Mike-T-Mitchell commented Jan 15, 2015

Thanks so much for making this gist.

Much appreciated!

Copy link

mloeser commented Feb 4, 2015

Ditto - thanks a ton - that finally fixed the mouse issue in Yosemite.

Copy link

bmb commented Feb 26, 2015

Nice. Unloading/loading the kernel extensions manually wasn't working for me, but triggering the action via sleepwatcher has got my stupidly expensive peripherals working again. Cheers!

Copy link

spotlightishere commented Mar 20, 2015

Thank you so much!

Copy link

nuthatch commented Apr 15, 2015

Exactly what I was looking for. "There must be a way to restart bluetooth on wake, that's when it's not responsive." Boom. Didn't know about sleep watcher.

Copy link

marinoluck commented Apr 30, 2015

excellent script man thanks a lot

Copy link

pmonks commented May 12, 2015

Great script - thanks for sharing!

Also, for those using homebrew, sleepwatcher can be installed via:

brew install sleepwatcher

Copy link

codehearted commented Jun 22, 2015

I just sent in my mac to get a host of issues fixed, this bluetooth sleep issue being the most critical that wasn't an obvious easy hardware replacement. It came back with the issue still there, but this fixes it (I used brew.)

Copy link

gh91745 commented Jul 7, 2015

I installed sleepwatcher via homebrew, but it won't run automatically when my iMac wakes up. Do I need to take an extra step to make the homebrew app run automatically upon wakeup? Thanks.

Copy link

inspiredearth commented Jul 16, 2015

Thank you very much. A simple cost-effective solution to a major Bluetooth failing on Mac Yosemite.

Copy link

BradGunnerSGT commented Jul 20, 2015

@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

Copy link

vegajulio commented Nov 22, 2015

Thanks a lot!!

Copy link

kyletolle commented Jul 29, 2017

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
# Sleepwatcher script to get bluetooth working after the mac wakes up
# Got this approach from
kextunload -b
kextload -b
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" "">
<plist version="1.0">
        <string>-s /etc/rc.sleep</string>
        <string>-w /etc/rc.wakeup</string>
sudo launchctl load /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-custom.plist

Copy link

miemo commented Dec 27, 2017

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: – 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):

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