Skip to content

Instantly share code, notes, and snippets.

@sharl
Created January 22, 2013 04:25
Show Gist options
  • Save sharl/4592024 to your computer and use it in GitHub Desktop.
Save sharl/4592024 to your computer and use it in GitHub Desktop.
OS X battery monitor script
#!/bin/sh
d=`/usr/sbin/ioreg -c AppleSmartBattery -r | /usr/bin/grep -E "MaxCapacity|CurrentCapacity|ExternalConnected" | /usr/bin/cut -d= -f2`
echo $d | while read MaxC CurC Ext; do
if [ $Ext = 'Yes' ]; then
echo "AC"
exit 0
else
p=`echo "scale=2; 100 * $CurC / $MaxC" | /usr/bin/bc`
echo "Batt $p%"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment