Sunday, May 24, 2009

Talking batteries

This post comes out of my necessity to preserve the battery life of my shiny new lenovo. I've heard that the key to preserving battery backup is to make sure you use your battery as much as you can and depend on AC power just to charge your battery. Since i don't run a full-fledged DE like GNOME or KDE there are no notification systems I could leverage to monitor my battery status.

Up until now I had to manually run "acpi" once in a while to check my battery status and take necessary action, and this process was a real pain in the ass especially when you are watching a movie and don't want to be disturbed. Thats why i decided to cough up a little script that would keep monitoring my battery status and "tell me"(literally) when either battery is low or battery has been fully charged.

Prerequisites
  • Festival text to speech system: Festival can read out text from stdout and hence is really handy. In Ubuntu/Debian-like systems you can run the following command to install festival.
sudo apt-get install festival

  • A small problem with the default installation of festival is that festival by default uses the outdated /dev/dsp to access your sound hardware. Hence festival cant say anything if you are using another application that has sound like mplayer for instance. To fix this you need to get festival to use ALSA. To do that run the following command from terminal.

printf ";use ALSA\n(Parameter.set 'Audio_Method 'Audio_Command)\n(Parameter.set 'Audio_Command \"aplay -q -c 1 -t raw -f s16 -r \$SR \$FILE\")\n" > ~/.festivalrc

Now download the following file and extract its content(battmon.sh) into your home directory

http://sites.google.com/site/r4jivn4ir/Home/battmon.tar.gz


Make the script executable by running

chmod +x battmon.sh

Now you need to setup this script to run during login. To accomplish that add the following line to the end of the file .xprofile which is present in your home directory. If such a file is not present create it.

./battmoh.sh &

From the next time you login, this script will keep checking your battery status and "tell you" whether you need to charge your battery or unplug your charger. Do test and let me know if it works :-)
Post a Comment