Created
April 17, 2010 17:34
-
-
Save gandro/369702 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
function get_property() { | |
cat /sys/devices/platform/smapi/BAT0/$1 | |
} | |
PREFIX="/usr/share/icons/gnome/24x24/status/" | |
while true ; do | |
PERCENT=$(get_property remaining_percent) | |
TIME= | |
STATE= | |
POWER= | |
if [ $(get_property state) == "discharging" ] ; then | |
STATE=" (entladend)" | |
elif [ $(get_property state) == "charging" ] ; then | |
STATE=" (ladend)" | |
fi | |
if [ ${STATE} ] ; then | |
if [ $(get_property state) == "charging" ] ; then | |
TIME=$(get_property remaining_charging_time) | |
else | |
TIME=$(get_property remaining_running_time) | |
fi | |
HOUR=$(expr ${TIME} / 60) | |
MIN=$(expr ${TIME} % 60) | |
TIME=$(printf ", %02d:%02d" $HOUR $MIN) | |
fi | |
ON_AC=$(cat /sys/class/power_supply/AC/online) | |
if [ ${ON_AC} = "1" ] || [ ${STATE} ] ; then | |
AC="Netzbetrieb" | |
else | |
AC="Akkubetrieb" | |
fi | |
if [ $(get_property power_now) -gt 0 ] ; then | |
POWER=", "$(get_property power_now)" mW" | |
fi | |
if [ ${ON_AC} = "1" ] ; then | |
ICON="battery-charging.png" | |
elif [ $PERCENT -ge 75 ] ; then | |
ICON="battery-full.png" | |
elif [ $PERCENT -ge 50 ] ; then | |
ICON="battery-good.png" | |
elif [ $PERCENT -ge 25 ] ; then | |
ICON="battery-low.png" | |
else | |
ICON="battery-caution.png" | |
fi | |
echo "tooltip: ${PERCENT}% ${AC}${TIME}${STATE}${POWER}" | |
echo "icon:${PREFIX}${ICON}" | |
sleep 5 | |
done #| zenity --notification --listen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment