See battery percentage in Terminal and GeekTool

Feb 01, '10 07:30:01AM

Contributed by: Anonymous

I have been building up a number of commands that I can use in GeekTool. One that I wanted but couldn't find in other lists was the current battery capacity. This works for me:

ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}'
[robg adds: This worked as shown on my 10.6.2 on my MacBook Pro. To get it work in 10.5, though, I had to modify the command a bit; I found that this version works in 10.5:
ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}'
Note that the output above is set up for GeekTool, where you don't want a newline. If you want to run this in Terminal, you can change the printf bit (in either version) to read ...2f%%\n..., which will add a line break at the end.]

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100130123935998