Skip to content

Instantly share code, notes, and snippets.

@atn34
Created April 7, 2013 22:39
Show Gist options
  • Save atn34/5332873 to your computer and use it in GitHub Desktop.
Save atn34/5332873 to your computer and use it in GitHub Desktop.
Notifies you if your battery is below a certain threshold and isn't charging. I'm using it for xmonad
#! /bin/sh
#
# Script for notifying when battery is low
# Set it up as a cronjob with
#
# $ crontab -e
#
# put the following in your crontab file to check every minute
#
# * * * * * env DISPLAY=:0.0 <absolute path to script>
#
# get percentage of battery left
PERCENT=`acpi | cut -d , -f2`
PERCENT=${PERCENT%\%}
# only notify if percent is under WARNINGLEVEL
WARNINGLEVEL=10
# don't notify if battery is charging
if [ $PERCENT -lt $WARNINGLEVEL ] && acpi -a | grep 'off-line'
then
notify-send --urgency=normal "Battery low!" "$PERCENT% left"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment