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...