如何使用COCOA以编程方式获取当前电池电量[重复]

时间:2022-02-27 15:16:51

This question already has an answer here:

这个问题在这里已有答案:

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

如何使用与Leopard一起运行的cocoa框架获得当前的电池电量?

Currently I am getting it running a NSTask with:

目前我正在运行NSTask:

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

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

但我认为这是一种笨拙的做法。

Thanks

2 个解决方案

#1


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

我相信这个问题之前已经在这里被问过......这里有一些链接:

Battery status in OSX? (asked here before)

OSX中的电池状态? (之前问过)

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

它限制了我的链接数量,因为我是新的...但你应该在那里找到更多的链接

#2


Take a look at: http://forums.macrumors.com/showthread.php?t=474628

请查看:http://forums.macrumors.com/showthread.php?t = 474628

#1


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

我相信这个问题之前已经在这里被问过......这里有一些链接:

Battery status in OSX? (asked here before)

OSX中的电池状态? (之前问过)

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

它限制了我的链接数量,因为我是新的...但你应该在那里找到更多的链接

#2


Take a look at: http://forums.macrumors.com/showthread.php?t=474628

请查看:http://forums.macrumors.com/showthread.php?t = 474628