I would like to disable some power hungry services once I disconnect the power cord. Was thinking of creating a launchd agent that can monitor a file and run a script.

If there are other ways of doing this without purchasing a separate app, that would be OK as well. Although, preferred way would be to do it with existing macOS commands.

  • Which "power hungry services"? Perhaps the problem is "why are these services using a lot of power, and is there a way to fix it?"
    – benwiggy
    Feb 17 at 8:55
  • A cloud backup service that should really be doing its job when it is on AC power rather than when on battery.
    – HanSooloo
    Feb 17 at 19:23

2 Answers 2


You can use system_profiler to get this info.

% system_profiler SPPowerDataType | grep -i “current power source” -B10

You will get the current power source and the relevant details. For example, on my iMac, I get the following:

AC Power:
      System Sleep Timer (Minutes): 45
      Disk Sleep Timer (Minutes): 10
      Display Sleep Timer (Minutes): 10
      Sleep on Power Button: Yes
      Automatic Restart on Power Loss: No
      Wake on LAN: Yes
      AutoPowerOff Delay: 259200
      AutoPowerOff Enabled: 1
      Current Power Source: Yes.      <- This tells you this is the current power source
      DarkWakeBackgroundTasks: 0
      Display Sleep Uses Dim: Yes
      Hibernate Mode: 0
      High Standby Delay: 86400
      PrioritizeNetworkReachabilityOverSleep: 0
      Standby Battery Threshold: 50
      Standby Delay: 86400
      Standby Enabled: 1
  • Wondering if there is a way to detect it when it happens, i.e., via a call-back or monitoring a file change. I believe in older macOS versions, a file would change when the power state changed.
    – HanSooloo
    Feb 17 at 19:24
  • You would need a process continually running to detect this.
    – Allan
    Feb 17 at 19:36

To get notifications about power source changes, see IOPowerSources.h and the kIOPSNotifyPowerSource notification:


C-string key for a notification of changes to the active power source.

Use this notification to discover when the active power source changes from AC power (unlimited/wall power), to Battery Power or UPS Power (limited power). IOKit will not deliver this notification when a battery's time remaining changes, only when the active power source changes. This makes it a more effiicent choice for clients only interested in differentiating AC vs Battery.

Third Party: Power Manager

Power Manager can run a script when switching to battery power. Use the built-in task Run a script on switch to battery to create the event:

Power Manager on macOS

Power Manager is a commercial product which I work on. Feel free to get in touch and ask technical questions about how it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .