본문 바로가기

Tips/Mac

Advanced scheduling of Mac OS Wake and Sleep Time

Mac OS has a settings panel that allows you to schedule the Wake, Sleep and Shutdown time for your Mac, but there is only one sche


dule allowed, everyday, or every friday, or every weekend, and so on.  I wanted a different wake and shutdown time for the weekend and weekdays.


This is possible using cron, and the command line tool pmset.

The crontab below wakes the Mac up at 5pm every weekday and shut's it down around 2am.
On the weekend, the Mac wakes up at 10am, and still shuts down around 2am.

The important thing to remember, if you have your Mac set to go to sleep when not being used, is to make sure the last pmset command invoked, wakes the computer up 1 minute before you want the next command to run, if you don't, cron won't run, and you're schedule won't happen.

MAILTO=""

# Minute   Hour   Day of Month       Month          Day of Week        Command    
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)          

# At 17:01, set the wake time to 02:00, and the reboot timeto 02:02.  It should be awake from the next command.
1      17      *       *       *       /usr/bin/sudo /usr/bin/pmset repeat wakeorpoweron MTWRFSU 02:00:00

# At 02:01 (sat+sun), it should be awake from the previous command, set the wake time to 09:58, and shutdown at 2:02
1       2       *       *       0,6     /usr/bin/sudo /usr/bin/pmset repeat wakeorpoweron MTWRFSU 09:58:00 shutdown MTWRFSU 02:02:00

# At 02:01 (mon-fri), it should be awake from the previous command, set the wake time to 17:00, and shutdown at 2:02
1       2       *       *       1-5     /usr/bin/sudo /usr/bin/pmset repeat wakeorpoweron MTWRFSU 17:00:00 shutdown MTWRFSU 02:02:00

# at 10:01, set the wake time to 17:00 for the download scripts
1       10      *       *       *       /usr/bin/sudo /usr/bin/pmset repeat wakeorpoweron MTWRFSU 02:00:00

pmset requires root access to run, so you need to add it to the /etc/sudoer file.

<username>  ALL=NOPASSWD: /usr/bin/pmset  

where <username> is the name of user crontab is running under, most likely, your login name.