launchd – Is there a way to detect power state change from the command line?

Spread the love

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






Leave a Reply

Your email address will not be published. Required fields are marked *