Created
November 16, 2016 08:48
-
-
Save futurist/699b613cb15662199ceedd96e35e288f to your computer and use it in GitHub Desktop.
Sleep when battery below 20% in MacBook
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 | |
MODE=`/usr/bin/pmset -g | awk '/hibernatemode/ { print $2 }'` | |
LEFT=`/usr/bin/pmset -g batt | grep Internal | awk '{ print $2 }' | awk -F % '{ print $1 }'` | |
if [ $LEFT -lt 30 ] && [ $MODE != 3 ] ; then | |
{ | |
/usr/bin/logger -t "hibernatemode" "Battery level less than 30%; setting hibernatemode to 3" | |
/usr/bin/pmset -a hibernatemode 3 | |
} | |
elif [ $LEFT -gt 50 ] && [ $MODE != 0 ]; then | |
{ | |
/usr/bin/logger -t "hibernatemode" "Battery level greater than 50%; setting hibernatemode to 0" | |
/usr/bin/pmset -a hibernatemode 0 | |
rm /var/vm/sleepimage | |
} | |
fi | |
if [ $LEFT -lt 28 ] && [[ $(/usr/bin/pmset -g batt | grep 'Battery Power') ]] ; then | |
{ | |
pmset sleepnow | |
} | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment