Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

When I try :

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

I have this error :

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

Do you have any idea ?

Thanks a lot

like image 816
Tokytok Avatar asked Apr 13 '12 11:04

Tokytok


People also ask

How do I enable system events?

All events send messages by default. You can disable and enable which events are enabled as desired. On the Configuration page, select the events you want to configure, and click Actions > Enable or Disable.

Is not allowed assistive access (- 25211?

It means that DS2 does not have the permissions it needs to work correct. (10.12 and ealier OSs.)


3 Answers

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

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 Editor and the error should be gone.

like image 128
IluTov Avatar answered Oct 20 '22 21:10

IluTov


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?

like image 30
fanaugen Avatar answered Oct 20 '22 21:10

fanaugen


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.

enter image description here

like image 2
bluebinary Avatar answered Oct 20 '22 22:10

bluebinary