Adding battery life info to Spectrwm status bar

Posted: November 18th, 2012 | Author: | Filed under: FreeBSD, productivity | Tags: | No Comments »

I am still a novice user of spectrwm. When my Lenovo T420 died on me because of low battery, I decided to find out how to add battery life info on the status bar.

I borrowed from arch linux spectrwm wiki and modified it to my needs:

#loops forever outputting a line every SLEEP_SEC secs
while :; do
LIFE=`sysctl -n`
STATUS=`sysctl -n hw.acpi.battery.state`
if [ $STATUS -eq 1 ]
then echo -e " Battery Life: $LIFE% Status: Not Charging" ;
echo -e " Battery Life: $LIFE% Status: Charging"; fi
sleep $SLEEP_SEC

.spectrwm.conf should contain:

bar_action =

Right now the laptop doesn’t have power adapter connected and my status bar shows: Battery life: 92% Status: Not Charging

Mission accomplished.