Ever since I upgraded to Mountain Lion, I can't run my AppleScript code through the Java ScriptEngineManager.
The sample code found on Apple's page (link) returns null for the engine
object.
public static void main(String[] args) throws Throwable {
String script = "say \"Hello from Java\"";
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
engine.eval(script);
}
Anybody know of any workarounds?
I got it working by adding a file named "javax.script.ScriptEngineFactory" in the folder "META-INF/services" of my jar as ytw indicated.
I also have to change a bit of code: language seems to no longer be "AppleScript" but "AppleScriptEngine". So this should work:
public static void main(String[] args) throws Throwable {
String script = "say \"Hello from Java\"";
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine");
engine.eval(script);
}
At least this works on my MacOS X Mavericks with JDK 1.7.45...
I posted this issue on bugreport.apple.com (bug id: 12692742). I received this response:
20-Feb-2013 04:21 PM Apple Developer Bug Reporting Team : We think you had an install of Lion with JavaDeveloper. You upgraded to Mountain Lion, which removed (by design) all traces of previously installed Java SE 6 under /System. This left a functional SE 6 JDK bundle under /Library/Java/JavaVirtualMachines, but the contents of /System/Library/Java/Extensions were gone.
You can resolve this a couple ways:
1) Re-install the JavaDeveloper package on the Mountain Lion system.
2) Re-install Java for OS X by removing any JDK bundles under /Library/Java/JavaVirtualMachines and /System/Library/Java/JavaVirtualMachines and running 'java -version' or '/usr/libexec/java_home --request' to initiate install-on-demand.
3) Install Java 7 from Oracle, which bundles AppleScriptEngine.
Of the 3 options, #3 is the recommend one, as developers should be moving to Java 7 anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With