tell application "System Events"
if UI elements enabled is true then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script requires access for assistive evices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the forthcoming security dialog." with icon 1
end tell
set UI elements enabled to true
if UI elements enabled is false then return "user cancelled"
delay 1
end if
end tell
When I run this, I get an error. "Can’t set UI elements enabled of application to true"
Any ideas why this may be happening?
Extra info: OS X Yosemite
I just answered this basic question for someone recently. See my answer here.