Battery level?

Anyone know a way to check the battery level through a command-program, script, or KM macro? Or whether it is charging? I used to use a cute little App called Unplugged, but it is defunct. I want to know when the magsafe adapter has unplugged and when the battery is getting low, without my having to think to look at the menu bar indicator.

Use pmset to query the state of the power supply and battery.

Magsafe connected:
$ pmset -g ps
Now drawing from ‘AC Power’
-InternalBattery-0 100%; charged; 0:00 remaining present: true

Magsafe disconnected:
$ pmset -g ps
Now drawing from ‘Battery Power’
-InternalBattery-0 100%; discharging; (no estimate) present: true

Magsafe disconnected, two minutes later (now with estimate):
$ pmset -g ps
Now drawing from ‘Battery Power’
-InternalBattery-0 99%; discharging; 3:11 remaining present: true


Very cool! Thanks.

In case anyone stumbles across this six-year-old thread, here's another solution to the problem of the Unplugged app not being available, using a KM feature that didn't exist then, the Power Status Change trigger.

If you are using a macOS and Keyboard Maestro version which allows for use of the Execute (or Edit) Shortcut action, you can get a battery level reading from the ShortCuts "Get Battery Level" action.

If we call the ShortCut "Battery level" then we can:

  • bind a battery level integer string to a Keyboard Maestro variable name
  • branch on a Calculation condition in a KM If then else action

Perhaps something like this, run on a periodic trigger at some interval like 5 or 10 minutes.

Screenshot 2023-04-24 at 10.23.39

1 Like