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?