Problem
If I understand correctly, you want to enable GUI scripting from a command line.
Solution
I believe you will need to use the following code to enable GUI Scripting from within an applescript. That script can then be executed from the command line. You may want to exclude the display dialog as needed -- this script just presents the dialog to confirm that the GUI settings have been made active.
if enabledGUISCripting(true) then
-- GUI Scripting statements go here
display dialog "GUI Scripting is enabled"
else
--non-GUI scripting statements go here
display dialog "GUI Scripting is disabled"
end if
on enabledGUISCripting(switch)
tell application "System Events"
activate
if not (UI elements enabled) then set (UI elements enabled) to true
return (UI elements enabled)
end tell
end enabledGUISCripting
The key parts of this are:
tell application "System Events"
activate
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
You could combine the key parts mentioned above into a file and tell osascript to execute it using:
osascript file.scpt
If you want to send osascript multiple commands on a single line instead of using a script file you could try (note multiple -e flags per command):
osascript -e “line 1″ -e “line 2″ -e “line 3″
You may want to run this using sudo (if needed):
If you get an error such as this one when running such scripts from Terminal you will need to enable accessibility for Terminal in the privacy preferences (Mavericks, see image below)
execution error: System Events got an error: Can’t set UI elements enabled of application to true. (-10006)
System Preferences > Security & Privacy > Accessibility (Click to enable Terminal)
permissions denied error
message ? – Thomas Ayoub