The Power Supply Status is a bash script application that uses Zenity to show the current battery status on your desktop notification area. See how it looks like:
#!/bin/bash
# Power Supply Status - Version 0.1
# Copyright 2007 Aurelio A. Heckert <aurium#gmail-com>
# Based on a previw work by Antonio Terceiro:
# http://twiki.softwarelivre.org/pub/Blogs/BlogPostAntonioTerceiro20080306161112/power-supply
#
# This software draw and updates a icon on the notification
# area, showing current battery status.
#
# This is a Free Software relized under the terms of
# the GNU-GPL: http://www.gnu.org/licenses/gpl-3.0.html
###################################################
# CONFIGURE HERE AS YOU NEED
###################################################
updateDelay=5 # seconds
alertPct=10
power_supply_alert(){
aplay /usr/share/orage/sounds/Spo.wav
}
c1EmptyR=230
c1EmptyG=0
c1EmptyB=0
c1MiddleR=200
c1MiddleG=120
c1MiddleB=0
c1FullR=0
c1FullG=150
c1FullB=0
c2EmptyR=150
c2EmptyG=0
c2EmptyB=0
c2MiddleR=120
c2MiddleG=70
c2MiddleB=0
c2FullR=0
c2FullG=80
c2FullB=0
baseSVG=$( echo "$0" | sed 's/\/[^\/]*$/\/battery-base.svg/' )
###################################################
# YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW HERE
###################################################
resultSVG=$( mktemp )
function interpolation() {
echo "p=($3/100); $1*(1-p) + $2*p" | bc -l
# one float point digit: | sed 's/\(\.[0-9]\).*$/\1/'
}
function getC() {
type=$1
c=$2
pct=$3
if [ "$pct" -lt 33 ]; then
pos1=Empty
pos2=Middle
pct2=$(( ( $pct * 31 ) / 10 ))
else
pos1=Middle
pos2=Full
pct2=$(( ( ( $pct - 33 ) * 15 ) / 10 ))
fi
eval "c1=\"\$c$type$pos1$c\""
eval "c2=\"\$c$type$pos2$c\""
interpolation $c1 $c2 $pct2 | sed 's/\..*$//'
}
while true; do
# battery
BATTERY_DEVICE=$(hal-find-by-property --key info.category --string battery | head -n 1)
if [ "${BATTERY_DEVICE}" != "" ]; then
pct=$(hal-get-property --udi ${BATTERY_DEVICE} --key battery.charge_level.percentage)
else
pct=0
fi
# AC Adapter
AC_DEVICE=$( hal-find-by-property --key info.category --string ac_adapter | head -n 1 )
[ "${AC_DEVICE}" != "" ] &&
AC_STATUS=$( hal-get-property --udi ${AC_DEVICE} --key ac_adapter.present | sed -e 's/true/on-line/; s/false/off-line/' )
if [ "$AC_STATUS" = "on-line" ]; then
tomadaRE=";"
else
tomadaRE="s/id=\"gTomada\"[^>]*transform=\"[^\"]*\"/transform=\"translate(100,0)\"/;"
fi
if [ $pct -gt $alertPct ]; then
alertRE="s/id=\"gAlert\"[^>]*transform=\"[^\"]*\"/transform=\"translate(100,0)\"/;"
else
alertRE=";"
if [ "$AC_STATUS" = "off-line" ]; then
power_supply_alert >/dev/null 2>/dev/null
fi
fi
y=$( interpolation 19 5 $pct | sed 's/\(\.[0-9]\).*$/\1/' )
fillPath="M 4.5,$y L 4.5,20 C 4.5,21 8,21.5 12,21.5 C 16,21.5 19.5,21 19.5,20 L 19.5,$y"
fillPathRE="s/M 4.5,8.5 L 4.5,20 C 4.5,21 8,21.5 12,21.5 C 16,21.5 19.5,21 19.5,20 L 19.5,8.5/$fillPath/g"
echo $( cat $baseSVG ) | sed "
s/#0101f1/rgb($(getC 1 R $pct),$(getC 1 G $pct),$(getC 1 B $pct))/g;
s/#0101a1/rgb($(getC 2 R $pct),$(getC 2 G $pct),$(getC 2 B $pct))/g;
$alertRE
$tomadaRE
s/cy=\"8\"/cy=\"$y\"/
$fillPathRE
" > $resultSVG
echo icon:$resultSVG
echo tooltip:AC: ${AC_STATUS} -- Battery: $pct%
sleep $updateDelay
done | zenity --notification --text="Power Supply Status" --listen
é modificado dinamicamente, ajustando-se a cor, posição, tamanho e a visibilidade de elementos, de acordo com as informações providas pelo HAL. O SVG resultante é entregue ao zenity para atualizar o ícone da bandeja.