Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to execute AppleScript from Java

I have a couple of AppleScripts that i want to run from Java. I have several options including:

  • Running the AppleScript as a string using the AppleScript ScriptEngine (using ((new ScriptEngineManager()).getEngineByName("AppleScript")).eval(scriptString)))
  • Saving the AppleScript as an Application and running the app from Java (using Desktop.getDesktop().open("name.app"))
  • Those two seemed the best options to me and I was wondering

  • Is there a better way?
  • If !(1.) Which of these two ways is the best? (Speedwise)
  • If !(1.) Are there ways to improve my methods?
  • like image 771
    Samuel Avatar asked Dec 28 '11 11:12

    Samuel


    2 Answers

    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.

    like image 122
    Gareth Davis Avatar answered Sep 19 '22 16:09

    Gareth Davis


    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.

    like image 20
    Monolo Avatar answered Sep 22 '22 16:09

    Monolo