-
-
Save sharl/4592024 to your computer and use it in GitHub Desktop.
OS X battery monitor script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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