Reputation: 18586
I have a couple of AppleScripts that i want to run from Java. I have several options including:
((new ScriptEngineManager()).getEngineByName("AppleScript")).eval(scriptString))
)Desktop.getDesktop().open("name.app")
)Those two seemed the best options to me and I was wondering
Upvotes: 6
Views: 2060
Reputation: 13972
I would guess that option 1 might be your best bet, because of how Applescript works.
There are two types of Applescript: plain text Applescript, then compiled Applescript. Complied Applescript has been translated (essentially) into bytecode by the Applescript complier.
Thus, if your application allows it, you may consider compiling all your Applescripts once, then calling them later. This will save you some time (seconds?).
(I'm just guessing here that, in addition to the eval
command, your Java class has a way to just compile Applescript.)
During the compilation stage, Applescript also tries to identify all the applications the script uses. I believe it's during this phase where Applescript might say, "I'm sorry, I can't find SurfWriter, please point me to the app". This kind of user experience is one of those things the user wants to do as little as possible ;)
Upvotes: 1
Reputation: 18253
Your first option sounds right to me, but if for some reason you want to run it as an external script, you could consider running an osascript the same way you would run a shell script.
Upvotes: 1
Reputation: 28069
Not sure I would go with 2, that seems like a very big hammer.
The other old style solution was to exec 'osascript' command.
As far as I know using the script engine support is the preferred method.
Upvotes: 1