Battery status API in macOS?

Alnitak picture Alnitak · Nov 7, 2008 · Viewed 15.3k times · Source

How can I read the status of the battery on my MacBookPro from my own application?

Googling has so far only revealed APIs for device drivers to handle power events - there's nothing about user-land processes accessing this information.

thanks.

Answer

Gary Chambers picture Gary Chambers · Jun 22, 2009

If you're looking for a quick way to query it from the command line, you'll find the pmset command helpful. To query the battery status, specifically, use:

$ pmset -g batt