Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix OSX battery draining on sleep due to wifi activity

Fix OSX battery draining on sleep due to wifi activity

Install SleepWatcher using Homebrew:

sudo chown -R $(whoami) /usr/local
brew update
brew install sleepwatcher

Start the SleepWatcher service:

sudo brew services start sleepwatcher

Create a Sleep and Wakeup file in your home directory:

touch ~/.sleep && chmod 744 ~/.sleep
touch ~/.wakeup  && chmod 744 ~/.wakeup

Put the following script into ~/.sleep to disable the wifi adapter:

#!/bin/bash
/usr/sbin/networksetup setairportpower en0 off
touch /tmp/sleep.log
cat > /tmp/sleep.log
echo "Sleeping: `date`" >> /tmp/sleep.log
echo `/usr/sbin/networksetup getairportpower en0` >> /tmp/sleep.log

Put the following script into ~/.wakeup to re-enable the wifi adapter:

#!/bin/bash
sleep 10
/usr/sbin/networksetup setairportpower en0 on
echo "Waking Up: `date`" >> /tmp/sleep.log
echo `/usr/sbin/networksetup getairportpower en0` >> /tmp/sleep.log

You can see the most recent sleep/wake cycle in the /tmp/sleep.log file:

cat /tmp/sleep.log

Notes

pmset -g log
pmset -g assertions
pmset -g sched
syslog | grep -i "Wake reason"
<Notice>: Wake reason: ARPT (Network)
<Notice>: ARPT: 255862.475269: ARPT: Wake Reason: Wake on Scan offload; Disconnect reason: Unknown
<Notice>: ARPT: 255862.601660: ARPT: Wake Reason: Wake on Scan offload

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.