Vote
Bury
16

Battery Status

Posted in System by Khelmar 252 days ago
This lists the battery status for MacBooks, and the current % if not attached to an AC adapter.

The shell script is:

my_ac_adapt=`ioreg -w0 -l | grep ExternalConnected | awk '{print $5}'`
if [ "$my_ac_adapt" == "Yes" ]
then
echo "Power : External"
else
cur_power=`ioreg -w0 -l | grep CurrentCapacity | awk '{print $5}'`
max_power=`ioreg -w0 -l | grep MaxCapacity | awk '{print $5}'`
bat_percent=`echo "scale=2;$cur_power / $max_power" | bc`
bat_percent=`echo "$bat_percent * 100" | bc | sed 's/.00//'`
cyc_count=`ioreg -w0 -l | grep "Cycle Count" | awk 'BEGIN { FS = "=" } ; {print $8}' | awk 'BEGIN { FS = "}" } ; {print $1}'`
echo "Power : Battery ($bat_percent%)"
echo "Cycles : $cyc_count"
fi


Just paste that into a file, set it executable, and run it as a shell command under GeekTool. Alternatively, just download the geeklet file linked below.

Screenshot 1:


Screenshot 2:

Geeklet file(s) to download

batterystatus.glet

Either right-click and choose "Save Linked File As..." or hold the Option key and click to download files.
If using Safari, you may have to rename the files without the extra .txt extension that is added.

Comments


Written by beiju
253 days ago
Is it possible to have it return successful when the battery is above, say, 10% but show GeekTool's "Failure" image when it gets below that?



Written by cndoval
152 days ago
Can someone wrap this one up into a downloadable geeklet?

Thanks



Written by matt
150 days ago
Done.



Log in to comment or register here.