26
votes

I have a Jenkins config that executes Java tests for OS X app using Maven. And when I'm trying to run some AppleScript that requires assistive access for it, different errors appear. So I've tried to execute AppleScript in two ways:

  1. Using ScriptEngine:

    ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine"); engine.eval(script);

In this case script execution fails with error: An error of type -10810 has occurred.

  1. Calling osascript. In this case error looks like: System Events got an error: osascript is not allowed assistive access. (-1719)

In accessibility list I have following things: SystemUIServer, Script Editor, osascript, java, mvn, bash, Terminal. When running script in Script Editor or in osascript from Terminal, script passed without any errors.

Any suggestions what else should I check?

4

4 Answers

17
votes

I think you answer your own question. You can allow assistive access for Script Editor (among other things). It works fine in Script Editor.

You can try and add other applications to have assistive access. This might be an option if Script Editor does not give you want you want.

enter image description here

1
votes

I've resolved something like this problem before by inserting osascript into the TCC.db using tccutil.py

After installing I linked tccutil.py into the path.

sudo ln -s /source/tccutil/tccutil.py /usr/bin/tccutil.py 

ls -l /usr/bin/tccutil.py 
lrwxr-xr-x  1 root  wheel  26 30 Dec 14:57 /usr/bin/tccutil.py -> /source/tccutil/tccutil.py

Then to allow osascript access to control your computer use the following compand

sudo tccutil.py --insert /usr/bin/osascript

I even added the script when the problem happened again later on.

sudo tccutil.py --insert $(pwd)/transcribe-audio-to-text.js

That failed so I rebooted which worked :-)

transcribe-audio-to-text.js currently uses System Events to make TextEdit be able to save a text file. It's part of virtual assistant which is very alpha at 20160105 but the source is interesting. virtual-assistant

1
votes

I find that I sometimes need to add the parent of the process that calls osascript, in addition to osascript itself, regardless of what the error message says. Sometimes I have to add the grandparent process too.

In particular, /bin/bash does not call any assistive API, but OSX wants it listed even though osascript is also listed, and I've had to add TeamCity's agent.jar too.

So try adding your .jar file, and look to see whether ScriptEngine uses an intermediate code executor that you'll also need to enable.

Beware that you'll probably have to remove and add your entries if you change the binary (I think OSX maintains some sort of checksum in the final binary entry in its database entry).

1
votes

Another workaround is to write the AppleScript using Script Editor, save it as a standalone app from there, and give that app assistive access. Then you can run the app as needed from another environment like a Java app or Automator workflow.

See also: https://apple.stackexchange.com/a/346306/264883