Some AppleScript from Java Applet no longer work with Mavericks
-
21-12-2019 - |
Question
I have an issue with the latest MacOS X version: Mavericks. I used to call AppleScript from a Java applet and everything worked fine on MacOS X 10.7.5. Going to Mavericks, I had to make few changes to make AppleScriptEngine
reachable again but even then, the scripts I'm running are returning an error.
Here is what I tried: My little piece of code:
private static final String SCRIPT =
"try\n"
+ " tell application \"Finder\"\n"
+ " delay 5\n"
+ " if exists application file id \"XCEL\" then return \"Excel found\"\n"
+ " end tell\n"
+ "on error errStr number errorNumber\n"
+ " error errStr number errorNumber\n"
+ "end try";
static void checkAppleScript() {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine appleScript = mgr.getEngineByName("AppleScript");
if (appleScript != null) {
JOptionPane.showMessageDialog(null, "AppleScript found: " + appleScript);
try {
JOptionPane.showMessageDialog(null, appleScript.eval(SCRIPT));
} catch (ScriptException se) {
JOptionPane.showMessageDialog(null, se.getMessage());
}
} else {
JOptionPane.showMessageDialog(null, "NO AppleScript engine");
}
}
I put this in a signed jar file with following attributes in the manifest:
- Trusted-Library: true
- Application-Name: TestingAppleScript
- Permissions: all-permissions
- Codebase: *
When I'm running a test class from the java command line, Excel is found on both MacOS X 10.7.5 and 10.9.1.
When I'm running a test applet from Safari, Excel is still found on MacOS X 10.7.5 but on 10.9.1 I got an error message: "Finder got an error: application isn't running".
I saw that this error may result in a too fast execution of the script, this is why I added the 5 seconds delay in my script but it does not solve the issue.
As I don't have any more ideas to try, I hope that someone will be able to help.
Solution
I finally found what was blocking: there is a security option in Safari to indicate that the Java plugin can run in unsafe mode for a given server. Activating this solved my issue.