[UPDATE - 2011-09-07] I just discovered, that the first script that i published here did a lot of errors, that were recorded in the log of mac os. I tweaked the script, so that the performance should go up a bit and these errors are dealt with. ;-) Please update your geeklet if you used the old version. Also set the refresh value to 60 sec or more. That should be more than enough.
I was upset that all the scripts i found for showing the Battery status for my Devices wouldn't work properly. This is my second revision which is based solely on ioreg and bash (first i used AppleScript in addition). It should work with all of your devices out of the box, but please send me a request if there's an error. It shows red status indicator if the battery percentage is 10 or below.
I don't own a magic mouse (as you can see in the screenshot), but it should work for it nevertheless. If not let me know.
Also if you're familiar with scripting in bash it shouldn't be a huge problem for you to modify the script, if you just want the percentage to be shown. If there is a request for a modified version i will upload it.
Have Fun with this!
Here is the code:
KeyboardPercent=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
typeset -i b=5
echo "Battery:\nKeyboard:\t\t\c"
if [ ${#KeyboardPercent} = 0 ]
then
echo "Disconnected\c"
else
if [ $KeyboardPercent -lt 11 ]
then
echo "\033[1;31m\c"
else
echo "\033[0m\c"
fi
while [ $b -le $KeyboardPercent ]
do
echo "|\c"
b=`expr $b + 5`
done
while [ $b -le 100 ]
do
echo "\033[1;37m|\033[0m\c"
b=`expr $b + 5`
done
echo "\033[0m $KeyboardPercent%\c"
unset KeyboardPercent
unset b
fi
echo "\033[0m\nMouse:\t\t\t\c"
MousePercent=`ioreg -c BNBMouseDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
if [ ${#MousePercent} = 0 ]
then
echo "Disconnected\c"
else
if [ $MousePercent -lt 11 ]
then
echo "\033[1;31m\c"
else
echo "\033[0m\c"
fi
typeset -i b=5
while [ $b -le $MousePercent ]
do
echo "|\c"
b=`expr $b + 5`
done
while [ $b -le 100 ]
do
echo "\033[1;37m|\033[0m\c"
b=`expr $b + 5`
done
echo "\033[0m $MousePercent%\c"
unset MousePercent
unset b
fi
echo "\033[0m\nTrackpad:\t\t\c"
TrackpadPercent=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
if [ ${#TrackpadPercent} = 0 ]
then
echo "Disconnected\c"
else
if [ $TrackpadPercent -lt 11 ]
then
echo "\033[1;31m\c"
else
echo "\033[0m\c"
fi
typeset -i b=5
while [ $b -le $TrackpadPercent ]
do
echo "|\c"
b=`expr $b + 5`
done
while [ $b -le 100 ]
do
echo "\033[1;37m|\033[0m\c"
b=`expr $b + 5`
done
echo "\033[0m $TrackpadPercent%\c"
unset TrackpadPercent
unset b
fi