I was recently running a long functional stress test against one of my projects. I came back 3 hours later, expecting to be 1/4 of the way complete and found that it only ran for 30 minutes because my computer fell asleep.
Changing my settings each time seemed like a pain, so I decided to look up a few options. I landed on the solution of Caffeinate. Here is how to use it:
For the most simple use, open a terminal and enter:
For a certain time, you can set a limit in seconds. This will run for ten minutes:
caffeinate -t 600
Or, you can tie the caffiene to a specific process or app. This will run as long as Safari is runing too:
caffeinate -i /Applications/Safari.app/Resources/MacOS/Safari