Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Created April 20, 2015 17:19
Show Gist options
  • Select an option

  • Save tjluoma/37fd89e21e46187d0198 to your computer and use it in GitHub Desktop.

Select an option

Save tjluoma/37fd89e21e46187d0198 to your computer and use it in GitHub Desktop.
#!/bin/zsh -f
# Purpose: This will show a MacBook’s current battery charge
# Intended to be used with TextBar - http://www.richsomerfield.com/apps/
/usr/sbin/ioreg -n AppleSmartBattery -r |\
awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}'
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment