Unix processes doesn’t have a name, only a number. And I don’t use Caffeinate so I don’t know what it expects really, but here is a way to get the unix pid anyway.
tell application "System Events"
set uxpid to unix id of application process "Safari"
end tell
(it is the least fuzzy one, but you can get it by using
do shell script " ps -ax |grep \"Safari\""
too I think.) (With some further filtering, as the grep command also will show up.)
I see that caffeniate is a unix utility that has been included in Mavericks.
I also see by the manual page that it takes a utility name as its argument.
Well, I think that to caffeniate the utility name, is what shows up in the output of the ps -ax command in a terminal window, so your “utility name” should then be: /Applications/Safari.app/Contents/MacOS/Safari.
A probable reason, is that the command you used didn’t reside in a folder that was in the path, so that caffeniate couldn’t find it. That’s my guess. A second guess would be that the file didn’t have the execute attribute set.
A third that the caffeinate utility can’t screen shell scripts. ( Some utilities doesn’t work with shell scripts for security reasons.)