caffeinate -i

Hi,

Does anyone know how to enter the process name:

do shell script "caffeinate -i 'Safari'"

→ error “Safari: No such file or directory” number 127
I’m thinking that the process has to be an executable. Need to try that next.

Edited: I can’t seem to enter the process name right:

do shell script "('/Users/kelhome/Desktop/ShellTest.sh' & caffeinate -i 'ShellTest')"

Thanks,
kel

Hello.

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.)

Hi McUsr,

I tried using the process id from the System Events return:

do shell script "caffeinate -i \"2680\""

→ error “2680: No such file or directory” number 127

I wonder if I need to change the directory and use the name of the process.

Edited: here’s the example from the man page:

Thanks,
kel

Interesting.

I see that caffeniate is a unix utility that has been included in Mavericks. :slight_smile:

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.

Try that, good luck!

Hi McUsr,

I think that did it:

do shell script "caffeinate -i '/Applications/Safari.app/Contents/MacOS/Safari'"

I wonder why using the path to my executable didn’t work. I’ll play around with this.

Thanks a lot,
kel

Hello.

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. :slight_smile: 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.)

Hi McUsr,

I used the full path to the script and your TextEditMakeExecutable script. :smiley:

do shell script "caffeinate -i '/Users/kelhome/Desktop/ShellTest.sh'"

It works! I think it was the full path with extension. The do shell script waits for the process to end! :slight_smile:

Edited: here’s a tester:

do shell script "caffeinate -di '/Users/kelhome/Desktop/ShellTest.sh'"
activate me
display dialog "Done. Now I can sleep!"

The display shouldn’t go to sleep until the executable ends! :slight_smile:

Thanks a lot and have a good day,
kel