Monday, September 7, 2009

debian openbox low battery warning using conky

${battery_bar 6,60 BAT0}
${battery BAT0}${if_match ${battery_percent BAT0} <= 20}LOWBATWARN${endif}${if_match ${battery_percent BAT0} <= 8}SHUTDOWNCOMMAND${endif}

This uses conky to warn of low battery status and run commands as needed.

Add colour and calls to commands as required.

~~~
~~~

Full Implementation..

${battery_bar 6,60 BAT0} ${battery BAT0}${if_match ${battery_percent BAT0} <= 20}${color orange} LOW BATERY!${color}${endif}${if_match ${battery_percent BAT0} <= 8}${if_match ${battery_percent BAT0} > 5}${execi 200 terminator -e ~/mybin/warn-shutdown}${endif}${endif}${if_match ${battery_percent BAT0} <= 5}${execi 200 terminator -e ~/mybin/shutdown-now}${endif}

calls this script on low power:

*warn-shutdown*

#!/bin/bash
echo "Low power. Do you want to shutdown? y or n"
read userconfirm
if [ "$userconfirm" != "y" ]; then
echo "Please connect power soon"
sleep 6s
exit 1
else
echo "ok, will shut down in 30 seconds. Rember to save :)"
sleep 30s
sudo shutdown -h now
fi
exit



and calls this script on VERY low power:

*shutdown-now*

#!/bin/bash
echo "Very low power. You need to shutdown."
echo "if you have connected power then press 's' to skip shutdown"
read -t 60 userconfirm
if [ "$userconfirm" != "s" ]; then
echo "ok, have to shutdown soon, 30 second warning..."
sleep 30s
sudo shutdown -h now
exit 1
else
echo "Ok, you say power is connected so shutdown skipped"
sleep 6s
fi
exit

0 comments: