Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions)
I'm extremely new to the language, but the script below did return a result the first time I ran it through Geektool. The only problem is that the variable did not match the result (batt at 95%, result was for 5% and below). It stopped working after that.
The percentage display works every time, but that's most likely because I didn't write that part of the script, I scavenged it. I'd rather use a variable than rerun the calculation over and over, but I couldn't get it to work.
#!/bin/bash
asbreg=`ioreg -rc "AppleSmartBattery"`
maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;
prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;
if [ 100*$curcap/$maxcap -gt 15 ] ; then
cp /Users/User/Desktop/Faces/Happy.png /Users/User/Desktop/Faces/Current/Current.png
elif [ 100*$curcap/$maxcap -gt 10 ] ; then
cp /Users/User/Desktop/Faces/Queasy.png /Users/User/Desktop/Faces/ Current/Current.png
elif [ 100*$curcap/$maxcap -gt 5 ] ; then
cp /Users/User/Desktop/Faces/Angry.png /Users/User/Desktop/Faces/Current/Current.png
elif [ 100*$curcap/$maxcap -gt 1 ] ; then
cp /Users/User/Desktop/Faces/Unconcious.png /Users/User/Desktop/Faces/Current/Current.png
fi
printf "%1.0f%%" ${prcnt};
#EOF