简体   繁体   English

从Java运行AppleScript时“不允许辅助访问”错误

[英]“is not allowed for assistive access” error when running AppleScript from Java

I have a Jenkins config that executes Java tests for OS X app using Maven. 我有一个Jenkins配置,使用Maven为OS X应用程序执行Java测试。 And when I'm trying to run some AppleScript that requires assistive access for it, different errors appear. 当我尝试运行一些需要辅助访问的AppleScript时,会出现不同的错误。 So I've tried to execute AppleScript in two ways: 所以我试图以两种方式执行AppleScript:

  1. Using ScriptEngine : 使用ScriptEngine

    ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine"); ScriptEngine engine = mgr.getEngineByName(“AppleScriptEngine”); engine.eval(script); engine.eval(脚本);

In this case script execution fails with error: An error of type -10810 has occurred. 在这种情况下,脚本执行失败并显示错误:发生了类型-10810的错误。

  1. Calling osascript . 调用osascript In this case error looks like: System Events got an error: osascript is not allowed assistive access. 在这种情况下,错误看起来像:系统事件出错:osascript不允许辅助访问。 (-1719) (-1719)

In accessibility list I have following things: SystemUIServer, Script Editor, osascript, java, mvn, bash, Terminal. 在可访问性列表中,我有以下内容:SystemUIServer,脚本编辑器,osascript,java,mvn,bash,终端。 When running script in Script Editor or in osascript from Terminal, script passed without any errors. 在脚本编辑器中运行脚本或从终端运行osascript时,脚本通过而没有任何错误。

Any suggestions what else should I check? 有什么建议我应该检查一下吗?

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. 如果脚本编辑器不能满足您的需要,这可能是一个选项。

在此输入图像描述

I've resolved something like this problem before by inserting osascript into the TCC.db using tccutil.py 我之前通过使用tccutil.py将osascript插入TCC.db来解决这个问题

After installing I linked tccutil.py into the path. 安装后我将tccutil.py链接到路径中。

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 然后允许osascript访问控制您的计算机使用以下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. transcribe-audio-to-text.js目前使用系统事件使TextEdit能够保存文本文件。 It's part of virtual assistant which is very alpha at 20160105 but the source is interesting. 它是虚拟助手的一部分,在20160105非常alpha,但来源很有趣。 virtual-assistant 虚拟助理

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. 我发现除了osascript本身,我有时需要添加调用osascript的进程的父进程,无论错误消息是什么。 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. 特别是,/ bin / bash不会调用任何辅助API,但OSX希望它列出,即使osascript也被列出,我也必须添加TeamCity的agent.jar。

So try adding your .jar file, and look to see whether ScriptEngine uses an intermediate code executor that you'll also need to enable. 因此,尝试添加.jar文件,并查看ScriptEngine是否使用您还需要启用的中间代码执行程序。

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). 请注意,如果更改二进制文件,您可能必须删除并添加条目(我认为OSX在其数据库条目的最终二进制条目中维护某种校验和)。

Another workaround is to write the AppleScript using Script Editor, save it as a standalone app from there, and give that app assistive access. 另一种解决方法是使用脚本编辑器编写AppleScript,将其另存为独立应用程序,并为该应用程序提供辅助访问。 Then you can run the app as needed from another environment like a Java app or Automator workflow. 然后,您可以根据需要从其他环境(如Java应用程序或Automator工作流程)运行应用程序。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM