Active Topics

 


Reply
Thread Tools
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#1
I believe that the following script will run
perpetually, checking the battery status
every five minutes. It will pop up a message
when the battery level falls below 10%.

Code:
#!/bin/sh
while true
do
sleep 300
X=`battery-status | awk '{print $4}'`
if [ "$X" \< "90" ]
then
  kdialog --title "Battery Status" --msgbox ". . . . . . . . .  $X  . . . . . . . . ."
fi
done
Some options in kdialog don't seem to work quite right but
the above works for me.

Of course, without the while loop, sleep etc the X=
and kdialog lines can form a script to get a popup
of the battery level whenever you want. But in that
case, this is better:

Code:
#!/bin/sh
X=`battery-status | awk '{print $4}'`
kdialog --geometry +15+450 --title "Battery Status" --passivepopup $X 4
geometry option does not work with msgbox - don't know why (but
that explains all the "dots").

You could put the first script in ~/.kde/Autostart

It does not seem to use any cpu that I can notice. One problem is
that the "busy cursor" bounces or blinks for the full timeout. I
wonder if there is a way to disable launch notification for particular
apps ...

Oh, and by the way, if you want to get rid of the script you'll
have to kill it from command line.
 

The Following User Says Thank You to albright For This Useful Post:
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#2
oops, can't edit these posts but of course the this line

[CODE][if [ "$X" \< "90" ]/CODE]

should be

[CODE][if [ "$X" \< "10" ]/CODE]
 
PinCushionQueen's Avatar
Posts: 538 | Thanked: 168 times | Joined on Dec 2007 @ Seattle
#3
Thanks a bunch albright!! I've tried out your "on demand" battery % indicator and it works great! I've switched to using it instead of battery-status mainly because I really like the unobtrusive little bubble. I've even set up a hotkey shortcut (Ctrl+B) to enable me to be able to check battery % with a couple of button presses while using any other app.

I haven't had a chance to test the <10% battery warning script yet - but should be able to get that low today. I think I might like it to warn me at 15 or 20% though - no rational reason really, I just prefer more warning. Can't I just replace the <"10" with <"15" and have it work?

Thanks again!
__________________
When you wish upon a star, your dreams really can come true... Unless it's an asteroid hurtling towards earth that will destroy all life.
 
penguinbait's Avatar
Posts: 3,096 | Thanked: 1,525 times | Joined on Jan 2006 @ Michigan, USA
#4
A script is provided in new KDE version to do this, it has a shortcut you can run at will on taskbar, and a background script that runs evry 10 minutes and notifys you when you are at 20%

NOTE you must have battery-status and python installed..
__________________
To all my Maemo friends. I will no longer be monitoring any of my threads here on a regular basis. I am no longer supporting anything I did under maemo at maemo.org. If you need some help with something you can reach me at tablethacker.com or www.facebook.com/penguinbait. I have disabled my PM's here, and removed myself from Council email and Community mailing list. There has been some fun times, see you around.
 
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#5
Can't I just replace the <"10" with <"15" and have it work?
Yes, certainly any value you want.

I don't know how PB has
implemented the battery monitor in the new kde package
but hopefully it is user configurable. Well, he just has
to tell us where the script is I guess

Plus you can add other commands to the script. For example,
this line (inserted just before the kdialog command):

Code:
  play-sound /usr/local/kde/share/sounds/KDE_Notify.wav
causes a little beep to go with the popup ...

It seems that perpetual scripts like these can stand in for
the missing cron demon (pending more knowledge about
how many resources they use up - it does not seem to
be noticeable but ...)
 
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#6
There's a problem with my script when the battery
gets below 10%. The string value e.g. "9.9%" is regarded
as *greater than* "10" (cause of the first character).

So, I suggest using the length of the battery-status
output. If it is less than 5 characters long then that
is the range less than 10% (since battery-status always
adds one decimal place).

Here's the new script

Code:
#!/bin/sh
while true
do
sleep 600
X=`battery-status | awk '{print $4}'`
if [ ${#X} -lt 5 ] && [ "$X" != "Charging" ]
then
  play-sound /usr/local/kde/share/sounds/KDE_Notify.wav
  kdialog --title "Battery Status" --msgbox ". . . . . . . . .  $X  . . . . . . . . ."
fi
done
I wonder what bugs are in this version
 
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#7
Here's another problem (not with the script though).

If the battery is fully charged then the battery-status
app hangs when run and returns no value and does not
exit.

A workaround that would avoid having instances of
battery-status accumulate might be to add something
like

Code:
killall battery-status
after the sleep 600 line ...
 
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#8
looks like the latest battery-status fixes the hang if
fully charged problem (though it now always reports
"charging" even when the battery is full). Thanks to
the author.

If you have flite installed, the tablet can tell you the
battery level, add lines like these in the appopriate
place:

Code:
X=`battery-status | awk '{print $4}'`
flite -t "battery status $X" &
P.S. it's tricky to do this in the tablet since the keyboard
lacks the " ` " symbol and the " ' " symbol (soft keyboard
has the latter)
 
Posts: 145 | Thanked: 32 times | Joined on Dec 2007
#9
I was wrong - the apostrophe is on the n810 hard
keyboard (on the key with question mark; looked to
me like a comma )

I respectfully changed PenguinBait's .xmap file to
include the left quote thus:

Code:
keycode  48 = apostrophe quoteleft question question question question
helps with scripting ...
 
Reply

Tags
battery, deprecated, kde, kde35


 
Forum Jump


All times are GMT. The time now is 09:02.