21

Battery Status

Posted in System by Khelmar 1679 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

Screenshot 2:

Screenshot

Geeklet files to download

Comments

User Avatar
beiju 1680 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?
User Avatar
cndoval 1579 days ago
Can someone wrap this one up into a downloadable geeklet?

Thanks
User Avatar
matt 1577 days ago
Done.

Log in to comment or register here.