Not authorized to send Apple events error
In some Mac OSx version — don’t remember the exact version — I noticed that all Apple Scripts run from JavaScript in InDesign to other applications (e.g. Excell) via the doScript command have stopped working producing the ‘Not authorized to send Apple events…’ AppleScript error. These scripts worked beautifully in older Mac OSx versions. As far as I understand, this problem occurred due to changes in Mac OSx. Unfortunately, I had no time to sort it out, and now after Russia began the war against Ukraine, like most of my compatriots, I lost my job and consequently access to my Mac so I can’t look into this problem. On the Adobe scripting forum, I found discussions on the topic, for instance, this post with solutions offered. For example, Kris Coppieters (RorohikoKris) got around it by ‘double-wrapping’ the AppleScript, and executing the problematic code by way of a command line invocation. Here's a snippet of his code:
var appleScript = "tell application \"Finder\" " + "to make alias file to POSIX file \"" + srcFilePath + "\" " + "at POSIX file \"" + dstFolderPath + "\""; var osaScriptCommand = "osascript -e \"" + backslashEscaped(appleScript) + "\""; if (srcFile.name != dstFile.name) { var intermediateFile = File(dstFolderPath + "/" + srcFile.name); var intermediateFilePath = intermediateFile.fsName; osaScriptCommand += "; mv \"" + backslashEscaped(intermediateFilePath) + "\" \"" + backslashEscaped(dstFilePath) + "\""; } var wrapperAppleScript = "do shell script \"" + backslashEscaped(osaScriptCommand) + "\""; try { app.doScript(wrapperAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE); } catch (err) { }
Other guys solved it, as far as I remember, by compiling an applet from the script.
Update: in August 2023, I tested it on Mac (Venture 13.4) in InDesign 17.0.1 and Excel 16.56, running the code in VS Code, and it works again but very slowly.