Tell me more ×
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. – Lauri Ranta 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

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.