AppleScript - 系统事件错误:辅助设备的访问被禁用 [英] AppleScript - System Events Error : Access for assistive devices is disabled

查看:22
本文介绍了AppleScript - 系统事件错误:辅助设备的访问被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AppleScript 和系统事件有问题.

I have a problem with AppleScript and System Events.

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

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

当我尝试时:

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

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

我有这个错误:

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

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

你有什么想法吗?

非常感谢

推荐答案

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

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").

您需要捕捉错误.这对我有用:

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

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

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?

这篇关于AppleScript - 系统事件错误:辅助设备的访问被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆