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

前端 未结 3 1947
傲寒
傲寒 2021-02-14 17:29

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

3条回答
  •  终归单人心
    2021-02-14 17:57

    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
    

    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?

提交回复
热议问题