Skip to content

Instantly share code, notes, and snippets.

@willgarcia
Created January 11, 2014 10:55
Show Gist options
  • Save willgarcia/8369459 to your computer and use it in GitHub Desktop.
Save willgarcia/8369459 to your computer and use it in GitHub Desktop.
mac geeklet - battery cycles
my_ac_adapt=`ioreg -w0 -l | grep ExternalConnected | awk '{print $5}'`
if [ "$my_ac_adapt" != "Yes" ]
then
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment