| View previous topic :: View next topic |
| Author |
Message |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 4:22 pm Post subject: Battery script |
|
|
Ok, my problem is this: Im using laptop to run gentoo and its quite usual that my laptop shutdowns several times every week cause im forgetting to plug power cable back and the battery runs out.
I though that if there would be a script (or littleprogram) which checks battery's state and changes the wallpaper to something else (to bright red one for example) when it goes below 5%, it would help me to notice it.
My knowhow is too little on these things that i could do that kind of prog/script, but if someone has little sparetime or knows a program which can do the above one, i really would appreciate that. |
|
| Back to top |
|
 |
Archangel1 Veteran


Joined: 20 Apr 2004 Posts: 1212 Location: Work
|
Posted: Tue Nov 23, 2004 4:36 pm Post subject: |
|
|
Interesting one... why not have a little battery monitor in some system tray type area?
Ala klaptopdaemon, no doubt XFCE has some similar dockapp thing, or you could use gkrellm/gdesklets or something along those lines to monitor it? |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 4:50 pm Post subject: |
|
|
yep... tried those (torsmo, gdesklet and gkrellm for example)... just too small... and those usually goes under other windows
but if the whole wallpaper would change i think i would notice that
dont want anykind of sound alarms... cause i dont keep my sounds on always
oh... and im using acpi... |
|
| Back to top |
|
 |
mangaf n00b

Joined: 20 Feb 2003 Posts: 6
|
Posted: Tue Nov 23, 2004 5:23 pm Post subject: |
|
|
| with klaptop you have options to launch a command and some options more, at two leves of battery charge |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 5:26 pm Post subject: |
|
|
klaptop is kde program ?
im using fvwm |
|
| Back to top |
|
 |
denstark l33t


Joined: 02 Jun 2003 Posts: 647 Location: bos.ma.us
|
Posted: Tue Nov 23, 2004 5:28 pm Post subject: |
|
|
| Riveri wrote: | klaptop is kde program ?
im using fvwm |
Well, that doesn't mean you won't be able to use it. You will, however, have to install all that kde crap. _________________ lol, its my blog.
penguinparty.org
| Quote: | < denstark> rws: why do you have to be so indian
< rws> can't help it. I am brown and poor. |
|
|
| Back to top |
|
 |
BlackEdder Veteran


Joined: 26 Apr 2004 Posts: 2568 Location: Dutch enclave in Egham, UK
|
Posted: Tue Nov 23, 2004 5:29 pm Post subject: |
|
|
| The info about your battery status is somewhere in /proc/acpi. I've no laptop so cn't check where precisely, but it should be super easy to write a script that checks the battery every minute and based on output sets your background. Info that is needed for that is mainly which program you are using to set your background now.. and where the info in acpi precisely is. |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 5:36 pm Post subject: |
|
|
AFAIK needed info is in two places
remaining capacity and design capacity
| Code: |
rave rave # cat /proc/acpi/battery/BAT0/state
present: yes
capacity state: ok
charging state: discharging
present rate: unknown
remaining capacity: 4268 mAh
present voltage: 14800 mV
rave rave # cat /proc/acpi/battery/BAT0/info
present: yes
design capacity: 4400 mAh
last full capacity: 4400 mAh
battery technology: rechargeable
design voltage: 14800 mV
design capacity warning: 440 mAh
design capacity low: 176 mAh
capacity granularity 1: 264 mAh
capacity granularity 2: 3960 mAh
model number: BAT0
serial number: 236
battery type: Lion
OEM info: SANYO
|
im using now fbsetbg for setting bg |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 5:42 pm Post subject: |
|
|
| denstark wrote: | | Riveri wrote: | klaptop is kde program ?
im using fvwm |
Well, that doesn't mean you won't be able to use it. You will, however, have to install all that kde crap. |
that's what i was afraid of.. |
|
| Back to top |
|
 |
denstark l33t


Joined: 02 Jun 2003 Posts: 647 Location: bos.ma.us
|
Posted: Tue Nov 23, 2004 5:48 pm Post subject: |
|
|
Seems very easy to do, but i don't know the proper way to cut the numbers from the text sring and then convert it to a numeric variable (i think I could be wrong)....
other than that, it should be very easy. _________________ lol, its my blog.
penguinparty.org
| Quote: | < denstark> rws: why do you have to be so indian
< rws> can't help it. I am brown and poor. |
|
|
| Back to top |
|
 |
BlackEdder Veteran


Joined: 26 Apr 2004 Posts: 2568 Location: Dutch enclave in Egham, UK
|
|
| Back to top |
|
 |
InfinityX Guru


Joined: 31 Jan 2004 Posts: 385
|
Posted: Tue Nov 23, 2004 6:29 pm Post subject: |
|
|
This seems to work well on my laptop:
| Code: | #!/bin/bash
declare -i battery
battery=`acpi | cut -d '%' -f1 | cut -d ',' -f2 | tr -d '\n'`
if [[ "$battery" < "5" ]]
then
fbsetbg red.jpg
fi |
You'll need to emerge acpi, and the syntax may be slightly different for your laptop. |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Tue Nov 23, 2004 7:05 pm Post subject: |
|
|
/usr/bin/battery
| Code: |
#!/bin/bash
path="/proc/acpi/battery/BAT0"
full=`cat $path/info|grep 'last full capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
current=`cat $path/state|grep 'remaining capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
state=$(( current * 100 / $full))
echo "$state"
|
~/battery
| Code: |
#!/bin/bash
declare -i battery
battery=`/usr/bin/battery`
if [[ "$battery" < "5" ]]
then
fbsetbg -f /home/rave/wallpapers/red.jpg
fi
|
ok... it works...
now, what would be the best way to run it ? crontab ? |
|
| Back to top |
|
 |
nightm4re Guru


Joined: 19 Jun 2004 Posts: 519 Location: Providence, RI, USA
|
Posted: Wed Nov 24, 2004 8:03 am Post subject: |
|
|
| Riveri wrote: |
ok... it works...
now, what would be the best way to run it ? crontab ? |
yep.. prolly the easiest way to do it. set it up for like every 5 minutes or something. _________________ Nitrogen - GtkMM based background setter/restorer, please test!
Minuslab | d.minuslab.net |
|
| Back to top |
|
 |
Riveri n00b


Joined: 20 Feb 2004 Posts: 65 Location: Tampere, Finland
|
Posted: Wed Nov 24, 2004 1:50 pm Post subject: |
|
|
if [[ "$battery" < "5" ]] -> if [[ "$battery" < "05" ]]
and it works right....
anyway, thanks to all who bothered to help me! |
|
| Back to top |
|
 |
aerandir n00b

Joined: 09 Jan 2004 Posts: 13 Location: Denmark
|
Posted: Sun Dec 05, 2004 8:25 am Post subject: |
|
|
if you are using gkrellm - you can define some extra alarms in the battery options - just set lower/alarm limit and any annoying little proggy youd like to get startet when the time comes
but gotto go back playing with my freshly installed compaq armada  |
|
| Back to top |
|
 |
|