osascript is not allowed assistive access. (-1728)
Script:
#!/usr/bin/osascript
tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.users"
delay 2
tell application "System Events"
click radio button "Login Items" of tab group 1 of window "Users & Groups" of application process "System Preferences"
end tell
end tell
How do I provide assistive access to this script? When running this through 'Script Editor', all it it needs is 'Script Editor' to be enabled under 'Accessibility' in 'Security & Privacy'.
But I need to run this (and some other similar script files) to be executed without user's intervention. I've tried saving the file in .sh, .app, .scpt, .applescript formats and run via terminal as sudo without any luck.
I've gone through other questions like this and other without any help.
EDIT: Thanks for the response guys. We've already tried these methods and they work without any doubt and that's where problem lies. We've way too many mac machines to go around and enable on them manually. We were hoping for some command that will add Terminal to the list with user's permission (kind of like UAC in Windows) or if possible silently.
If you run AppleScript code via osascript
in Terminal, then you need to add Terminal to System Preferences > Security & Privacy > Privacy > Accessibility, to allow it assistive access.
I took your code, saved it to a file named testcode
and made it executable using chmod
. I then ran it in Terminal and received the following error:
./testcode:157:286: execution error: System Events got an error: osascript is not allowed assistive access. (-1728)
I then added Terminal to System Preferences > Security & Privacy > Privacy > Accessibility and ran it again. It then processed the script properly and returned:
radio button Login Items of tab group 1 of window Users & Groups of application process System Preferences
It of course opened the System Preferences to that target.
I got an error like 636:751: execution error: System Events got an error: osascript is not allowed assistive access. (-1719)
even though I ran the osascript
command from iTerm 2 which was on the list of applications in "System Preferences > Security & Privacy > Privacy > Accessibility".
I stopped getting the error after I also added the System Events application (in /System/Library/CoreServices/
) to that list.
The key point in the linked answer is:
When you first load or run the LaunchAgents you will get a prompt to set the Assistive Access in System Preferences. If you already have System preferences open you will not but the Script text file will be added to the list.
You now just have to check its check box to allow it.
Step 1 is to open the security tab and allow your script app or the individual scripts permission to automate the interface.
Step 2 - profit and avoid error -1728