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
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.
Then, just check the checkbox left to the AppleScript Editor and the error should be gone.
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?
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.
Related
I have an applescript which reads a cell from filemaker. Since Mojave (OS 10.14) it fails with
error "FileMaker Pro 18 Advanced got an error: A privilege violation occurred." number -10004
I assume it has to do with the security features of Mojave. How can I fix this?
tell application "FileMaker Pro 18 Advanced"
tell document "test.fmp12"
tell table "customerTable"
set customerName to data of cell "nameOfCustomer"
end tell
end tell
end tell
the set command throws the error.
In System Preferences/Security & Privacy/Privacy
I gave full disc access to Script Editor and Filemaker Pro Advanced
did you go to File menu/Manage/Security and edit the Privilege Set to Allow Apple Events for the FMP file?
I have used a simple AppleScript that toggles between active and inactive macOS Mail accounts that has worked peachy up until macOS 10.15 Catalina. I generally trigger this through the Script Menu to hide one account and enable another, but have also tried by simply opening and running it. Either way, it's now failing with the error:
Blockquote error "Mail got an error: AppleEvent handler failed." number -10000
Here's the script: what am I missing here to having this work in Catalina?
tell application "Mail"
set enabled of account "Mac" to false
set enabled of account "Windows" to true
end tell
On earlier versions of OS X an applescript like :
tell application "System Events" to tell process "Google Chrome"
get position of window 1
click at {598, 260}
end tell
worked.
But it doesn't work anymore on Mavericks. Is it some kind of broken ?
PS: AppleScript Editor has access to the Accessibility.
Yes, it is. There's some discussion on Apple's site.
Yes. When I try to run
tell application "System Events" to click at {500, 500}
it works in a 10.8 VM but results in an error like System Events got an error: Can’t make {500, 500} into type list in 10.9.
You can use MouseTools instead:
do shell script "MouseTools -x 500 -y 500;MouseTools -leftClick"
This issue has been fixed on Yosemite (tested on Beta 5 and GM).
IS it possible to enable MAC OS X assistive technologies programmatically on Snow Leopard, Lion and Mountain Lion?
I've got a client with an application that needs the "Enable access for assistive device" checkbox checked in Universal Access. This is for an application that is expected to run on Snow Leopard, Lion and Mountain Lion.
Can it be done via an Applescript or a shell script embedded in an Objective C application or MUST it be enabled manually, explicitly by the user?
Here's what I use...
enable_GUI_scripting()
on enable_GUI_scripting()
try
if (system attribute "sysv") < 4138 then display dialog "This script requires the installation of Mac OS X 10.3 or higher." buttons {"Cancel"} default button 1 with icon 2
tell application "System Events" to if not UI elements enabled then
tell me
activate
display dialog "This script requires the built-in Graphic User Interface Scripting architecture of Mac OS X, which is currently disabled." & return & return & "Enable GUI Scripting now? (You may be asked to enter your password.)" buttons {"Cancel", "Enable"} default button 2 with icon 2
end tell
set UI elements enabled to true
if not UI elements enabled then error number -128
end if
return "yes"
on error
return "no"
end try
end enable_GUI_scripting
Try this :
tell application "System Events"
activate
set UI elements enabled to true
end tell
In OS X Lion apps automatically resume when the user logs in. My app is set to be a windowless agent without an icon in the Dock (LSUIElement is set to YES in Info.plist) and it doesn't resume when I restart my machine.
According to Apple documentation all applications get the Resume behaviour by default and the developer doesn't need to do anything special to enable it. Are LSUIElement apps a special case? Is there anything that needs to be done to enable them to Resume?
From my own testing, LSUIElement applications are not resumed. So yes, they appear to be a special case – you'd need to ask Apple why this is the case, but setting this value appears to forcibly disable resume.