Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created March 30, 2010 15:26
Show Gist options
  • Save mmisono/349199 to your computer and use it in GitHub Desktop.
Save mmisono/349199 to your computer and use it in GitHub Desktop.
#!/bin/sh
ioreg -n AppleSmartBattery | \
awk '/MaxCapacity/ {MAX = $5}
/CurrentCapacity/ {CURRENT = $5}
/InstantTimeToEmpty/ {REMAIN = $5}
END {
printf("HP%d ",CURRENT/MAX*100)
if(REMAIN > 1000)
if(CURRENT == MAX) printf("(Charged)")
else printf("(Charging)")
else printf("(%d:%02d)",REMAIN/60,REMAIN%60)
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment