tell application "System Preferences"
    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.

  • In my case, the caller was Alfred 3. It wasn't getting added to the list automatically so I just manually added it to Accessibility and then my script call worked. – Chris Redford Jun 14 '18 at 18:01
  • 3
    I have the same error even-though I have terminal in Security & Privacy – Kevin Jul 8 '18 at 10:02

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.

  • Surprising that this worked. Wish I knew why. I added all of the other more obvious applications first... to no avail. – Del Brown Feb 7 at 1:12
  • You are my life-saver. – alswl Feb 14 at 7:23

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.

enter image description here

Step 2 - profit and avoid error -1728

  • 1
    Unfortunately this doesn't actually work for me with a LaunchAgent, my logs show execution error: System Events got an error: osascript is not allowed assistive access. (-1719) and I don't get prompted by System Preferences to allow assistive access. macOS 10.12.6 – swrobel Jul 28 '17 at 1:34
  • Try adding also osascript to "Assistive Access" – at least internally, AppleScript treats "osascript" NOT as simply a command but as a process of its own. . . . Paste following code into ScriptEditor: . . . tell application "System Events" to do shell script "osascript -e 'tell application \"System Events\"\n display dialog (items of (name of (every process whose name contains \"sc\") as list) as string)\n end tell'" . . . and you'll see a list of (sadly not "delimetered") processes with "osascript" towards its end. – clemsam lang Nov 25 '18 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .