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 baraction.sh from arch linux spectrwm wiki and modified it to my needs:

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

.spectrwm.conf should contain:

bar_action = baraction.sh

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

Mission accomplished.