macos AppleScript - 系统事件错误:辅助设备的访问被禁用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10140334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 09:04:15  来源:igfitidea点击:

AppleScript - System Events Error : Access for assistive devices is disabled

macosapplescript

提问by Tokytok

I have a problem with AppleScript and System Events.

我有 AppleScript 和系统事件的问题。

I have check "Enable access for assistive devices" in the “Universal Access” preference pane in System Preferences.

我在“系统偏好设置”的“通用访问”偏好设置面板中勾选了“启用辅助设备访问”。

When I try :

当我尝试:

arch -i386 osascript -e 'tell application "System Events" to get the position of every window of every process'

arch -i386 osascript -e '告诉应用程序“系统事件”获取每个进程的每个窗口的位置'

I have this error :

我有这个错误:

System Events got an error: Access for assistive devices is disabled. (-25211)

系统事件出错:辅助设备的访问被禁用。(-25211)

Do you have any idea ?

你有什么主意吗 ?

Thanks a lot

非常感谢

采纳答案by fanaugen

The problem is not the assistive devices. AppleScript seems to incorrectly return that error code when it tries to access windows of a process that can never have any windows (in my case it was "Google Chrome Helper").

问题不在于辅助设备。当 AppleScript 尝试访问一个永远不会有任何窗口的进程的窗口时,它似乎错误地返回了该错误代码(在我的情况下它是“Google Chrome Helper”)。

You need to catch the errors. This works for me:

您需要捕获错误。这对我有用:

tell application "System Events"
    set procs to processes
    set windowPositions to {}
    repeat with proc in procs
        try
            if exists (window 1 of proc) then
                repeat with w in windows of proc
                    copy w's position to the end of windowPositions
                end repeat
            end if
        end try -- ignore errors
    end repeat
end tell
return windowPositions

returning a list of coordinate pairs, such as {{1067, 22}, {31, 466}, {27, 56}, {63, 22}, {987, 22}} – is that what you were trying to get?

返回坐标对列表,例如 {{1067, 22}, {31, 466}, {27, 56}, {63, 22}, {987, 22}} – 这就是您想要得到的吗?

回答by IluTov

On Mac OS X 10.9 you actually get the same error when the AppleScript Editoris not allowed to use Accessibility.

在 Mac OS X 10.9 上,当AppleScript 编辑器不允许使用辅助功能时,您实际上会遇到相同的错误。

Here's how you enable it:

以下是启用它的方法:

Go to System Preferences> Security & Privacy> Privacy> Accessibility.

转到系统偏好设置>安全和隐私>隐私>辅助功能

enter image description here

在此处输入图片说明

Then, just check the checkbox left to the AppleScript Editorand the error should be gone.

然后,只需选中AppleScript 编辑器左侧的复选框,错误就会消失。

回答by bluebinary

Similar to the post on this page about Mac OS X 10.9 (Mavericks), to resolve this issue on Mac OS X 10.8 (and likely on earlier versions of OS X also), you need to ensure that the "Enable access for assistive devices" option has been enabled in the Accessibility pane of System Preferences.

类似于此页面上关于 Mac OS X 10.9 (Mavericks) 的帖子,要在 Mac OS X 10.8(也可能在早期版本的 OS X 上)解决此问题,您需要确保“启用辅助设备的访问”选项已在系统偏好设置的辅助功能面板中启用。

enter image description here

在此处输入图片说明