Battery status in OSX?

三世轮回 提交于 2019-11-26 22:11:05
Ben Gottlieb

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).

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

Look at the System Management Controller. I don't have my MBP handy, but I believe you need to look at smc.h

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!