How to Schedule Sleep and Wake Events from Terminal in Mac OS X

Dec 18, 2009 - 6 Comments

Terminal in Mac OS X

Like many of us, I’m often busy and out of the home, leaving my Mac on a desk. I regularly use my home machine as a local fileserver though and other people in the household are dependent on it being up and running. Now here’s the situation I’m presented with: I leave town earlier than my housemates do, but I don’t want to have to rely on someone who is not particularly computer savvy to put my Mac to sleep, so what do I do? Schedule the sleeping and waking events, of course! And in this case, it’ll be done through the command line.


Yes, most users should and can schedule sleep events from the Energy Saver preference panel in Mac OS X, but this is aimed more at advanced individuals who, perhaps, want to adjust this behavior remotely, and that’s what the Terminal allows for. And, being a bit on the geeky side, I’ll do this from the command line, which serves two purposes:

1) it’s geeky

2) it is exactly what you could do if you are currently away from your Mac but want to schedule sleep and wake remotely.

Scheduling Mac Sleep & Wake Events from the Command Line in Mac OS X

Here’s how you can schedule sleep and wake via the command line, remember you can do this remotely by SSH’ing into the Mac you want to schedule:

pmset schedule sleep "12/24/2009 00:00:00"

Now my system will go to sleep on Christmas Eve, the 24th of December.

pmset schedule wake "12/26/2009 00:00:00"

This command insures that my Mac wakes up the day after Christmas

That’s all there is to it! Now my Mac will sleep and wake on it’s own, independent of anyone else interfering with the machine.

Note that you can do all of this through the Energy Saver / battery system preference GUI too but that’s not as fun (for me at least).

Another perk to using the command line approach is that this can be easily modified remotely or with a setup script, so

.

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS, Tips & Tricks

6 Comments

» Comments RSS Feed

  1. Alejandro says:

    Hi, very useful, however only for 1x wake-sleep cycle… If I wanted to wake and sleep every day 11:00am-2:00pm, but also wake only on Sunday 8:00pm and sleep Sunday 11:00pm, I haven’t managed to set 2x or more schedules… Many thanks in advance.

  2. Andrew says:

    Hi,

    Nice tip.

    Before the computer goes to sleep it brings up a dialogue saying if nothing is done it will shut down in 10mins.

    Is there a way to remove this prompt? There’s nothing in the pref pane.

    Thanks again

  3. Chip says:

    lost: no, you just need to run it with “sudo” in front of the “pmset….” it just wants to make sure you’re a system admin :)

  4. lostinasafari says:

    hi, i tried this, and its telling me “pmset: this operation must run as a root” is it because i have 10.6? :P

  5. BitterMacFace says:

    @Carl, yes the pmset command changes are reflected in Energy Saver panel, you’ll notice that any setting made by pmset beyond the norm adjusts things within the preferences GUI to “Custom”

    pmset has a ton of other possibilities, like timing boots, shutdown, sleep, I am about 95% sure the Energy Saver GUI is just a front end to the pmset command itself.

  6. Carl says:

    Nice. Even faster than using the GUI. Are the scheduled event added through pmset reflected in the energy saver prefpanel? Also, is it possible to schedule reccuring events through pmset? (I know I could try it out or check the man page, but I feel lazy + It’s somewhat a good point of discussion)

    cheers.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site