Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active March 25, 2024 13:42
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ziadoz/7bddcf346adb89da1e990126c9f82429 to your computer and use it in GitHub Desktop.
Save ziadoz/7bddcf346adb89da1e990126c9f82429 to your computer and use it in GitHub Desktop.
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