#!/bin/sh # # battery-monitor # Written By: Dean Jones # # Monitors the battery status via APM and spits the # results out via osd_cat # # If the battery is over 20%, display is in Grey, else # If the battery is over 10%, display is in Yellow, else # If the battery is over 5%, display is in Orange Red, else # If the battery is under 5%, display is in Red. # # If you have the osd_cat binary in a strange area, # You can specify the full path in the variable # OSD_CAT (below), or put the path to it in $PATH # # If you do not have the JMK Neep font, you can change # the FONT variable (below) to the font you'd like to use. # OSD_CAT= FONT="neep-14" level= percent= ac_online= time= # Figure out what Color to display with osd_cat # by considering the percent level osd_print () { color= refresh= case "$percent" in [0-5]%) color="red" refresh=60 ;; [6-10]%) color="orange red" refresh=90 ;; [11-20]%) color="yellow" refresh=120 ;; *) color="gray" refresh=180 ;; esac echo "Battery Status: $ac_online $level $percent" | "$OSD_CAT" -f "$FONT" -p bottom -A right -d "$refresh" -c "$color" -o -15 } # Set the level name based on the percent of the # battery life that is left. # # < 0, No Battery # 0 - 5, Critical # 6 - 19, Low # 20 - 100, High # # If AC is online and battery is less than 100% # level should be "Charging" set_level () { if [ -z "$percent" ] then level="No Battery" elif [ "$ac_online" ] && [ "$percent" != "100%" ] then level="CHARGING," else case "$percent" in [0-5]%) level="CRITICAL,";; [6-19]%) level="LOW,";; *) level="HIGH,";; esac fi } # First check to make sure they have osd_cat test -z ${OSD_CAT:=`which osd_cat 2> /dev/null`} && echo "Error: Can't find osd_cat. Please make sure it's in your \$PATH" && exit # This is our main loop while apmstat=(`cat /proc/apm`) do # 0x01 means an AC cord is attached. if [ "${apmstat[3]}" = "0x01" ] then ac_online="AC Online," fi # -1% means no battery, no percent to display if [ "${apmstat[6]}" != "-1%" ] then percent="${apmstat[6]}" fi set_level osd_print done