Battery status API in macOS?
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
You'll want to use IOKit for this, specifically the IOPowerSources functions. You can use IOPSCopyPowerSourcesInfo()
to get a blob, and IOPSCopyPowerSourcesList()
to then extract a CFArray out of that, listing the power sources. Then use IOPSGetPowerSourceDescription()
to pull out a dictionary (see IOPSKeys.h for the contents of the dictionary).