Scripting Addition (Not Script Library) Question: pre-Mojave. Doesn't Run As A Service

I researched the topic before posting here: it turns out the issue used to be widespread since 10.6 but the problem is there’re many references but no ultimate solution.

I have a third-party standard addition which development was quite expectedly stopped with the premiere of Mojave. I can run the code containing statements from its dictionary in Script Editor, Script Debugger and Automator but as soon as I put it together as a part of an Automator Service (known by the name of Quick Action since Mojave) or Script Menu item that runs by choosing from the global script menu it stalls. I see the workflow gear spinning but the actions from the script addition’s commands that are supposed to kick in do not. I can stop it only by killing Automator Runner in Terminal.

If I run a script containing this scripting addition from the global script menu the part that contains the addition simply blanks.

Speaking of Terminal, as a test, I executed the automator utility on the troubled service with verbose logging. It returned the message I encountered a lot in the past when running shell scripts involving osascript without any degrading effect. Here it is as seen on the command line:

automator -v /Path/To/Services/MyService.workflow

Get Selected Mail Items is running

Get Selected Mail Items is finished

Run AppleScript is running

Automator Runner: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/QXPScriptingAdditions.osax" cannot be used with the current OS because it has no OSAXHandlers entry in its Info.plist

It’s the Run AppleScript point where everything halts. The most interesting thing is that it’s not QXPScriptingAdditions.osax that I call in my script. Furthermore, the scripting addition I use resides in my home folder, not a volume library.

Permissions are OK.

In another, an iteration older system:

  1. When I run the bit in Automator it throws an error to the effect that it “doesn’t understand the command” although it compiles seamlessly

  2. When I run it as an executable AppleScript script from the target application’s script menu Console shows error -10004 which is a privilege violation error. What does make it raise such an error when I run it as a legitimate user and the owner of both the script and the processes?

What’s wrong then? Does a possibility of reconciling the issue exist?

I presume you are using a pre-Mojave version of macOS. WIth Mojave and later versions of macOS, Scripting Additions are no longer supported due to increased security restrictions.

I think this error tells you why commands from the scripting addition fail to run:

There are many ways to configure a scripting addition, and in this instance the OSAXHandlers plist entry is required. It may be that somehow this plist entry got stripped along the way - I can only speculate.

Moving on to why you are able to compile scripts, but not run them. The AppleScript compiler only requires the scripting additions dictionary meta-data (‘aete’) to compile your script and convert the commands and other identifiers defined by the scripting addition into their internal coded form. The AppleScript runtime, which must load and execute code from the scripting addition, does not participate in the compilation process.

Later, when the script executes, the AppleScript runtime will fail to load the scripting addition at startup (issuing the error you quote), but will execute your script. Later when the script attempts to call a scripting addition command, there will be a event not handled failure.

Error reporting will very depending on the run-time environment (script menus, automator, terminal, etc.). The bottom line is that attempts to invoke missing commands from the scripting addition will fail, and cause an AppleScript exception. If this exception is not handled, the script will abort. If the exception is handled incorrectly, you may experience endless loops that appear to be hangs.

I’m at a loss to explain why you are able to successfully run your script from the Script Editor. By ‘home’ folder, are your referring to ~/Library/ScriptingAdditions? If not, then you’ll need to make sure you place the scripting addition in this folder.

Yes, I talked about ~/Library/ScriptingAdditions/. Since I left off the thread I did a couple of analogous tests on the same Automator service running the shell automator command with the verbose mode turned on in the other older macOS I mentioned briefly at the bottom of my original message and got the following even more detailed response:

Starting Automator…
Get Selected Mail Items is running

Get Selected Mail Items is finished

Run AppleScript is running

Automator Runner[12486:707] Error loading /Users/home/Library/ScriptingAdditions/24U Appearance OSAX.osax/Contents/MacOS/24U Appearance OSAX:  dlopen(/Users/home/Library/ScriptingAdditions/24U Appearance OSAX.osax/Contents/MacOS/24U Appearance OSAX, 262): no suitable image found.  Did find:
/Users/home/Library/ScriptingAdditions/24U Appearance OSAX.osax/Contents/MacOS/24U Appearance OSAX: GC capability mismatch
Automator Runner: OpenScripting.framework - can't find entry point AGUI_DisplayBetterDialog in scripting addition .
The action “Run AppleScript” encountered an error.

That, in fact, echoes what I said about the inability to run AppleScript scripts from outside Script Editor and Automator and in the latter case it fails even in Automator. On the GUI level this corresponds to the

Choose a contact from the pop-up menu to add the E-mail address to." doesn’t understand the display better dialog message.

error followed by the termination of the workflow. 24U Appearance OSAX is the standard addition in question and better dialog message belongs to its commands. By default, it was installed in /Library/ScriptingAdditions with somewhat erroneous permissions (those of my user). Both elevating them to system:wheel and moving to the same folder of my home library with my:staff didn’t change anything.

Running a AppleScript script containing 24U Appearance OSAX on the command line with osascript -so /Path/To/Scripts/Applications/MyScript.scpt bears no actions and produces no standard output at all.

There’s no solution to it, right?

Today, I saw this when I tried to execute a script, containing the same osax, from Firefox. I can swear I used to run it without a hitch. I cannot trace back to the event that caused this mess but I know it used to work as I wanted it to (click to view the screenshot because Imgur won’t allow previews).

I double checked I don’t have the scripting addition’s duplicates. Still, “restricted”, out of nowhere.