Can I configure a task to run while my MacBook lid is closed?

Can I use pmset or a utility like Power Manager to have a task (such as an arbitrary script or backup) run at a specific time while my Mavericks MacBook Pro's lid is closed? Are there perhaps pmset settings I need to change to make such a thing work?


While the lid is closed, a pmset wake will only wake up your machine very briefly, after which it will go back to sleep again. To keep the machine awake long enough to preform a task, you can caffeinate the machine for the amount of time (in seconds) you expect the task to take. For example, to keep the machine awake for 2 minutes, simply add

caffeinate -t 120 &

early on in the script that runs your task.

Alternatively, caffeinate has options for tying the duration of the forced wake period to the completion of the task, but this runs the risk of keeping the machine awake indefinitely, so a safer bet is this expected-time-based approach.