I have a Java program that I run in Eclipse which executes AppleScript for certain tasks. It works fine in Mojave, but in Big Sur, the AppleScripts fail with the error "AppleScript Not authorized to send Apple events to [app] (-1743)"
In Mojave, the user is prompted (one time on the first run) with "'Eclipse.app' wants access to control '[app being controlled by Applescript]'" Once this prompt is approved, then Eclipse is added in the System Preferences under Security & Privacy -> Privacy -> Automation and a checkbox is included and activate for each of the applications that the AppleScript manipulates (Finder and iTunes or Music app depending on OS version), and thereafter, my Java program can run its AppleScripts.
In Big Sur, the prompts never appear and the AppleScript immediately errors out. Furthermore, I see no way to manually add approvals under System Preferences -> Security & Privacy -> Privacy -> Automation and there is no way I can find for how I can approve this automation on my own Mac.
How do I invoke AppleScript on Big Sur from other languages such as Java?
Please note that the Java program constructs AppleScript content at run time dependent on data, so the scripts are not fixed.
The Java code to run a script goes like this....
Thanks in advance for any help!
In Mojave, the user is prompted (one time on the first run) with "'Eclipse.app' wants access to control '[app being controlled by Applescript]'" Once this prompt is approved, then Eclipse is added in the System Preferences under Security & Privacy -> Privacy -> Automation and a checkbox is included and activate for each of the applications that the AppleScript manipulates (Finder and iTunes or Music app depending on OS version), and thereafter, my Java program can run its AppleScripts.
In Big Sur, the prompts never appear and the AppleScript immediately errors out. Furthermore, I see no way to manually add approvals under System Preferences -> Security & Privacy -> Privacy -> Automation and there is no way I can find for how I can approve this automation on my own Mac.
How do I invoke AppleScript on Big Sur from other languages such as Java?
Please note that the Java program constructs AppleScript content at run time dependent on data, so the scripts are not fixed.
The Java code to run a script goes like this....
Java:
String script = <Some expression to form the content of the script depending on data>;
String[] myargs = { "osascript", "-e", script};
try {
Process process = runtime.exec(myargs);
process.waitFor(); // Wait for the script to complete before checking success/fail.
if (process.exitValue() == 0) { // Success
//On Mojave, execution takes this path and Applescript works, after the one time user approval.
System.out.println("success");
} else { // Fail
//On Big Sur, executions takes this path and outputs
//35:57: execution error: Not authorized to send Apple events to Finder. (-1743)
InputStream is = process.getErrorStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
} catch (Exception exc) {
System.out.println(exc.getMessage());
}
Thanks in advance for any help!