Caffeine is a useful utility that keeps your Mac awake when activated—useful if you want to prevent your Mac from sleeping so it can carry out a specific task. But you don’t need to download a third-party app in order to do the deed: Instead, you can simply use a Terminal command to replicate the function.
- Open the Terminal app. (Applications/Utilities/Terminal.app)
Caffeinate &into the Terminal then press the Return key.
- If you want to prevent your Mac from sleeping for a certain length of time, use the modifier -t between
&, like so:
Caffeinate -t 7200 &
The Caffeinate command-line tool requires you to enter the duration in seconds, so in this example, we want our Mac to stay awake for 7200 seconds, or two hours. If you don’t have your hours-to-seconds unit conversions memorized, you can always type a query like “2 hours in seconds” into Spotlight to get an instant unit conversion.
- You can also set this up as an Automator Trigger or Shell Script. There are additional options you can find by entering
man caffeinatein the Terminal.
Source: Brett Terpstra