Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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:

Screenshot

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?

share|improve this question
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 '12 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. –  Mathias Bynens Aug 12 '12 at 19:44
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Very cool trick — thanks! Unfortunately this poses a potential security risk, as now any apps could make such changes as well. –  Mathias Bynens Dec 15 '13 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. –  Graham Miln Dec 15 '13 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. –  Mathias Bynens Dec 15 '13 at 20:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.