Stopping Mac going to Sleep

thanks Tim.

caffeinate maybe a way forward, is there a way to call the terminal app without having it show on screen, gain focus, type the command and then exit?

also looking at the arguments. if i had my app called SpecialK would the argument look like this:

caffeinate -SpecialK ? e.g does it check to see if the process is still running, and if not hen “de-caffeinates”