Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Enabling GUI scripting via AppleScript

So I have a launch-daemon that needs to utilize GUI scripting. I need to be able to enable it through AppleScript (or really any scriptable, automated means). I am trying to do this:


tell application "System Events" to if not UI elements enabled then

set UI elements enabled to true

return UI elements enabled

end if


but it doesn't seem to do anything. The return query is just to check that it worked, but it never does. I have tried saving the script and running it as administrator (sudo osascript myScript.scpt) but it still doesn't work. I never get prompted for admin credentials. This occurs when logged in as administrator or non-admin user. Any ideas?

Posted on Nov 12, 2012 5:25 PM

Reply
19 replies

Mar 30, 2015 10:16 AM in response to VikingOSX

Hmm, that works for me too but the code in my previous post fails. Any idea why?


I tried to write a script that toggles GUI-scripting:


tell application "System Events"

if not UI elements enabled then

set UI elements enabled to true

else

set UI elementenabled to true

end if

return UI elements enabled

end tell

but it fails when trying to turn it off. Why?

Mar 30, 2015 11:10 AM in response to Hate when you ask for personal details

On Lion, there is a checkbox in System Preferences > Universal Access panel on Lion. It is at the bottom of the "Seeing" tab contents:

Enable Access for Assistive Devices


The AppleScript, set UI element enabled to true, when a password is applied to that challenge dialog box, enables this checkbox on the Universal Access panel. I suspect that UI elements will remain enabled until one programmatically sets UI element enabled to false, or manually deselects this checkbox in the Universal Access panel. In the latter case, rerunning the AppleScript will produce the challenge dialog again.

Enabling GUI scripting via AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.