I’d like to use the osascript shell command to run some AppleScript, but I’d rather avoid the GUI password prompt. Instead, I’d prefer to run the script as sudo from the command-line, so no GUI popups/prompts are needed.

The command is the following:

osascript -e 'tell application "System Events" to set UI elements enabled to true'

Running this command has the same effect as going to System PreferencesAccessibility and checking Enable access for assistive devices.

If it doesn’t prompt for your password, try the opposite:

osascript -e 'tell application "System Events" to set UI elements enabled to false'

For either one of these commands you’ll get a password prompt in the OS X GUI:


My question is: is there any way to avoid this password prompt?

I assumed invoking osascript with sudo privileges would do the trick, but alas — even in that case the GUI prompt is shown. :(

sudo osascript -e 'tell application "System Events" to set UI elements enabled to true'

Is there a way around this?

  • 1
    I don't know if was just an example, but you can also enable access for assistive devices with sudo touch /var/db/.AccessibilityAPIEnabled.
    – Lri
    Aug 12, 2012 at 14:56
  • 1
    @Lri echo -n 'a' | sudo tee /private/var/db/.AccessibilityAPIEnabled > /dev/null 2>&1; sudo chmod 444 /private/var/db/.AccessibilityAPIEnabled (as used here) more closely mimics what enabling the setting in System Preferences does, although it’s not instant (unlike going through SysPrefs manually). Any idea on which service to restart after this command? Anyhow, as you guessed, it was just an example. Aug 12, 2012 at 19:44

1 Answer 1


You can suppress the password interface by modifying your Mac's authorization rights.

Use the built-in security command line tool or authbuddy to change the system.preferences.accessibility right to allow:

sudo security authorizationdb write system.preferences.accessibility allow

Opening up the system.preferences.accessibility right will permit any user to change the accessibility settings without a password prompt.

  • Very cool trick — thanks! Unfortunately this poses a potential security risk, as now any apps could make such changes as well. Dec 15, 2013 at 18:47
  • Only authenticated administrators may alter authorization rights. allow is one of many possible rules to test against and other rules are available to choose from or to create. The security manual page shows how to apply alternatives. Dec 15, 2013 at 19:14
  • Yes, only authenticated administrators can run the above script (sudo) — but I meant that after that, all apps on the system are able to change accessibility settings at will. Dec 15, 2013 at 20:03
  • how do we reverse this process?
    – ikel
    Apr 20, 2019 at 5:59
  • @ikel Please could you ask a new question. Comments are less visible on this site and a new question will better attract answers. Feel free to mention this question and answer in the new question. Apr 20, 2019 at 6:48

You must log in to answer this question.

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