Big Sur - AppleScript thru Java - Not authorized to send Apple events to [app] (-1743)

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

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

The TCC subsystem, which is responsible for the controls under System Preferences > Security & Privacy > Privacy, needs to be able to map from the process that performed the authorised operation to the ‘responsible code’, that is, an app that the user knows about. Without this there’s no way that TCC can present a meaningful alert. If TCC is unable to do this mapping then it fails secure, that is, the operation just fails.

Something about the way that your app is constructed has broken the TCC mapping. I see this all the time in Java apps and it’s not exactly clear as to what that is. Java does many non-standard things, so there’s a bunch of possibilities.

First things first, is your app’s main executable a script?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Solved. Thanks for the reply.

In Big Sur, I had previously tried the terminal command

tccutil reset AppleEvents

and it did not seem to help, although it did remove the approvals of the other apps I had approved in Security & Privacy -> Privacy -> Automation.

Later Eclipse IDE would not start at all giving two errors immediately at launch. "You do not have permission to open the application 'Eclipse.app'" and "eclipse quit unexpectedly". Furthermore, Eclipse did not appear in GateKeeper so I could not grant a permission for it to run. I reinstalled Eclipse IDE 2021‑09 from the .dmg provided by the Eclipse organization and found it also fixed my issue running AppleScript from Java, as I was presented with the appropriate requests for permissions when I ran my Java program.

Just to answer the reader question...

First things first, is your app’s main executable a script?

The main executable is a Java class and I run the code from within Eclipse. But that is moot at this point.

Big Sur - AppleScript thru Java - Not authorized to send Apple events to [app] (-1743)
 
 
Q