You are not logged in.

#1 2008-03-22 17:33:18

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

[Solved] Light battery monitoring tool

I'm looking for a small lightweight battery monitory for openbox to sit in my tray. If none exists, is there a file that displays the percent left so I could just cat the file and call in in the openbox pipe menu?

Thanks.

Last edited by Reasons (2008-03-23 01:42:48)

Offline

#2 2008-03-22 18:36:57

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: [Solved] Light battery monitoring tool

Conky have the functions needed (http://conky.sourceforge.net/variables.html look for battery)

The file is in /proc/acpi/battery/BAT? with it you can calculate the percentage using the 'last ful' from info and remaining from 'state'

acpitools provide a simple awkeable interface.

Offline

#3 2008-03-22 21:44:48

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Re: [Solved] Light battery monitoring tool

I've tried conky before and am trying to move away from it.

Offline

#4 2008-03-22 22:05:46

nDray
Member
From: Portugal
Registered: 2007-01-21
Posts: 143
Website

Re: [Solved] Light battery monitoring tool

you can run acpi (package acpi, extra repository, i guess).

Offline

#5 2008-03-22 22:28:24

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: [Solved] Light battery monitoring tool

Found this script:

#!/bin/bash
current=`grep remaining /proc/acpi/battery/BAT1/state | awk {'print $3'}`
full=`grep full /proc/acpi/battery/BAT1/info | awk {'print $4'}`
percent=`echo "($current*100)/$full" | bc`
echo $percent

You need bc installed and you have to do a ls /proc/acpi/battery/ to check if your battery is a BAT0 or a BAT1.

Offline

#6 2008-03-22 22:29:13

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: [Solved] Light battery monitoring tool

This is one way to do it:

acpi -b | sed 's/^.*\: //g;s/%,.*/%/g'

If you just want the percentage:

acpi -b | sed 's/.*[dg], //g;s/\,.*//g'

You need "acpi" package installed for the above commands to work.  If you don't want to use the acpi command for some reason:

#!/bin/sh                                                                                                   
battery_max=`cat /proc/acpi/battery/BAT1/info | head -3 | tail -1 | sed 's/[^0-9]//g'`                        
battery_current=`cat /proc/acpi/battery/BAT1/state | head -5 | tail -1 | sed 's/[^0-9]//g'`                   
battery_level="`echo "100 * $battery_current / $battery_max" | bc`"                                           
battery_state=`cat /proc/acpi/battery/BAT1/state | head -3 | tail -1 | sed 's/.*[[:blank:]]//g'`              
                                                                                                              
if [ "${battery_state}" = "charged" ]; then                                                                   
    echo $battery_state;                                                                                      
else                                                                                                          
    echo $battery_state, $battery_level%;                                                                     
fi

Offline

#7 2008-03-23 01:25:41

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: [Solved] Light battery monitoring tool

gbatt. that's what i used when i used flux. also may be of intrest, gvtray and gtim

edit: http://code.google.com/p/gtk-tray-utils/

Last edited by rson451 (2008-03-23 01:26:34)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#8 2008-03-23 01:42:35

Reasons
Member
From: Washington
Registered: 2007-11-04
Posts: 572

Re: [Solved] Light battery monitoring tool

fwojciec, thanks. Really what I was looking for. Just put that into a pipe menu and it's all good.

Offline

Board footer

Powered by FluxBB