Search code examples
objective-ccocoapower-management

How to programmatically get current battery level with Cocoa


How can I get the current battery level using the Cocoa framework running with Leopard?

Currently I am getting it running a NSTask with:

pmset -g ps | grep -o -e [0-9]*% | sed -e 's/%//g'

But I think this is a clumsy way of doing this.


Solution

  • I believe this question has been asked here before... Here's some links:

    Battery status in OSX? (asked here before)

    It limited my number of links because I'm new... but you should find more links there