I’ve been using Caffine for Mac to prevent my mac from sleeping until I found this terminal command that comes with Mountain Lion and up.
Just launch the Terminal App and type
caffeinate -u -t 14400
Change the number to the number of seconds you want your mac to be active before going into sleep. Your Mac will not engage into sleep mode until the time set in the caffeinate on the terminal is complete .If you want to end the command hit Ctrl+C.
To get the full options for caffeinate just type
I still prefer to use the Caffine app because it makes the job easier with just one touch.