Is it possible to write a script to change the Energy Saver settings in OS X (10.7.3)?

Basically, whenever I know I'm going to be gone, or if I'm going to sleep, I change the Energy Saver settings in System Preferences in OS X (10.7.3) for Power Adapter to:

  • Computer sleep: 1 min
  • Display sleep: 1 min

If I know I'm going to be around a while, I like to change the Energy Saver settings for Power Adapter to:

  • Computer Sleep: 15 min
  • Display Sleep: 15 min

Is it possible to script this sort of change? I do it often enough that a script would be worth it.


Look for the section titled "Changing Power Management Settings" in this MacScripter guide. An AppleScript example from the guide:

do shell script "pmset sleep 30" with administrator privileges