I am trying to execute osascript from a Java Appliction.
I’m using Java’s Runtime.exec() function to execute the following:
/usr/bin/osascript -e ‘tell application “Safari”’ -e ‘open location “http://www.google.com”’ -e ‘end tell’
When I run my Java code, nothing happens. There is no error when the command is executed, but Safari does not appear. I’ve checked the return value of the process, and it is 1. This leads me to believe that I am running into some sort of problem, since 0 usually indicates success.
Unfortunately, the manpage of osascript does not describe what the error return codes are, so I have no way of knowing if 1 is OK or not.
I’ve tried the exact same command from Terminal, and it works fine.
Any help would be greatly appreciated.
I just posted a question along the same lines as yours (except I’m using PHP’s exec) a couple of days ago. Run console and see if there’s a permissions error generated in sys log when you run your jar. Not sure if your problem is the same, but it’s worth a shot.
I think osascript’s “e” parameter does not accept multiline statements, nor you can concatenate multiple "e"s to a osascript call. In your example, you can:
/usr/bin/osascript -e 'tell application "Safari" to open location "http://www.google.com"'
Thanks for your replies.
I don’t see any errors in the Console, so I don’t think this is my problem.
I also tried ‘tell application “Safari” to open location “http://www.google.com”’, but it didn’t make any difference.
Incidentially, I was able to run the command with multiple ‘-e’ options in Terminal, so I think it works OK…