Run macro only when using the battery

Is it possible to trigger a macro when the laptop is just using the battery and disable it when it goes back to using the charger?

I have issues with my laptop warning me on time that I'm low on battery and I would like KM to warn me about it. I have a macro that I run every 30 minutes, whether I'm using the battery or not and it works. I was just wondering if I can trigger it only when necessary, not every 30 minutes

There is a Power Status Changed Trigger, but the way you describe how you want your macro to function it seems that a scripted probing for the battery status and an If-statement would do the trick.

The command line pmset -g ps also returns battery percentage, and estimated time remaining until battery is empty, that can be utilised to make your macro even more precise.

Notify IF Running on battery power Macro (v10.2)

Notify IF Running on battery power.kmmacros (3.7 KB)


I do have a macro that does that, which is running every 30 minutes.
My goal is to avoid it running every 30 minutes and only triggering it when the laptop is running on battery only. I always have it plugged in to the charger and that's useless that I have it running the macro every 30 minutes. So as soon as the laptop is not plugged in to the charged, it would trigger the macro and only then, run it every 30 minutes. As soon as I plug it in again, it would cancel the macro.

Hope it makes sense

Not sure if this is possible at all anyway

In this case you could utilise the mentioned Power Status Changed Trigger. Not on my Mac now but I’d set it up as a separate macro that every time the Power Status changes would check if the Mac is now running on battery power, (i think you could use a Trigger Value token to do this, or you could use the same command line as in my last post). IF it is running on battery power THEN Enable the notifify-every-30-minutes-macro, ELSE Disable this same macro.

As @Alexander said, you want the Power Status Changed trigger. You can use a switch action to then enable or disable whatever macro(s) you need. A sample macro is below, just verify the actual trigger value when run, (the alert action at the top of the macro will return the values for your reference, you can delete it and the clipboard action once you have it set up), and update the “contains” fields appropriately (because I can’t remember what they are right now), and then select the macro(s) you want to enable/disable below the comment actions.

Download Macro(s): Toggle macro upon power source change.kmmacros (5.6 KB)


  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6
  • Keyboard Maestro v10.2
1 Like