View Single Post
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