I run a lot of scripts on my computers and some of those scripts can run for minutes or even hours (for example scripts which archive large directories). So it is more than annoyance if the computer decides to go to sleep while the script is running.
There is a useful OSX command caffeinate which will stop the
machine from sleeping for the duration of a subcommand passed
in the command line argument. Google to see what command line
flags caffeinate takes.
Example caffeinate command:
caffeinate -i java -classpath some.jar some.class.name some arguments for java