I have a method with a simple shell command to see whether or not Photoshop is running before continuing on.
If it is, it continues on with another method, and if it’s not it quits.
When Photoshop is open, sh.result returns true. As it should.
However, the if condition never runs. It goes straight to the else condition.
Code:
sh = new shell
dim cmd as string
cmd = "/usr/bin/osascript -e 'running of app id ""com.adobe.photoshop""'"
sh.Execute(cmd)
s = sh.Result
if s = "true" then //if sh.result = "true" then
ProcessImages()
else
MsgBox("Please open at least 1 image in Photoshop before running AutoCrop.")
quit
end if
I’ve been working with shell.Result recently and found some other issues, hope this is helpful. In addition to the encoding issues and end-of-line issues above, also watch for these:
Some utilities return 1 or more blank lines before and/or after the actual results.
Tabular results may have 1 or more header lines.
Default timeout of 2 seconds is often OK but not always - I’ve been using 5 seconds. OK to use more for a background task that a user isn’t waiting on.
Be prepared to have your application break if the utility changes the format of it’s output for any reason.
Agreed. I don’t understand how it’s safe to use the result of a shell command in several situations; when an API is available for the same task, I’d always prefer it over some formatted strings.
To check whether an application is running, there are other ways (including an API, the MBS plugin (the Process class) and “System Event”).