Skip to content

Instantly share code, notes, and snippets.

@lotherk
Created April 12, 2018 19:11
Show Gist options
  • Save lotherk/0a7925f9f398f178fc2c2f2ea8b1cee5 to your computer and use it in GitHub Desktop.
Save lotherk/0a7925f9f398f178fc2c2f2ea8b1cee5 to your computer and use it in GitHub Desktop.
#!/bin/sh
MIN=5
WARN=10
BAT_TIME=$(sysctl -a |grep battery.time |awk -F ' ' '{print $2}')
test -f /tmp/battery.lock && exit 1
touch /tmp/battery.lock
do_exit() {
rm -f /tmp/battery.lock
exit $1
}
if test $BAT_TIME -lt 0 || test $BAT_TIME -gt $WARN; then
rm -f /tmp/battery.notified
do_exit 0
fi
if test $BAT_TIME -lt $MIN; then
sudo acpiconf -s 3
do_exit 0
fi
if test $BAT_TIME -lt $WARN; then
if test ! -f /tmp/battery.notified; then
xmessage "Battery time is ${BAT_TIME} < ${WARN}"
touch /tmp/battery.notified
fi
fi
do_exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment