Search code examples
objective-cmacoscocoaiokit

IOKit get current power source


How do I get the current power source on a Mac, using IOKit?

I want to see if the Mac is running via the built-in battery or via a power adapter.


Solution

  • The functions in IOPowerSources.h (specifically, IOPSGetProvidingPowerSourceType()) will give you the info you're looking for.