Automatic password entry for change in "System Events"??

Hi,

I found that the following simple script will automatically check the “Enable access for assistive devices” box in the Universal Access pane of System Preferences and thereby enable GUI scripting for “System Events”:

tell application "System Events" to set (UI elements enabled) to true

The problem is that it results in a popup window asking for my password in order to effect the change. Is there any way to incorporate the password into the script and thus eliminate the password prompt?

bmose

That’s not true on my machine (I run as Administrator, OS X 10.4.5), so you must be running without administrative privileges. Is that true, and what is your system?

Hi Adam,

Thanks for the reply. I am also running OS X 10.4.5, and I’m pretty sure I’m running with administrator privileges (in the Accounts pane, I am listed as “Admin”, and “Allow user to administer this computer” is checked.)

bmose

My bad, bmose - mine was already checked. When I unchecked it and ran your one-liner I also got a request for a password as I do if I try to set it false. That is interesting because checking the box in the pane does not require admin privileges AFAIK. I couldn’t find an alternative, since System Events doesn’t understand passwords itself. Sorry.

Is there a way to achieve the same result with a Terminal shell script (do shell script “…”)? Perhaps that could achieve the same end result without the password prompt problem.

Actually the advantage of a shell script here is that it is easy to include a password. See the last post here for example.

Adam,

I tried your code for running a Terminal shell script with the user’s password, and it works nicely. Thank you for that pearl. Now if there were only a way to enable UI elements in Terminal!

Drives me nuts. I tried this, and System Events still asks for a password.

set Ss to "osascript -e 'tell application \"System Events\" to set (UI elements enabled) to true'"
set PW to getPswd()
do shell script Ss password PW with administrator privileges

to getPswd()
	tell application "Keychain Scripting"
		launch
		tell current keychain to ¬
			tell (some generic key whose name is "ASPW")
				return password
			end tell
	end tell
end getPswd

Good try! What are we missing???

I’m of the opinion that this is either a bug or that Apple regards the ability to enable gui scripting from a script (rather than from the panel itself) to be a security problem. I guess I can “sortta” see that. The message says that System Events is doing the requesting, but SE doesn’t have the word “Password” in its dictionary. In the details section of the Authenticate dialog, it says “Requested right: system.perferences.accessibility”, but there is no file by that name anywhere that I can detect it. I admit that I’m stumped.

I also saw that reference to “system.preferences.accessibility” but likewise couldn’t find the file anywhere. This may very well represent an active security decision on Apple’s part. So barring any new discoveries, I am leaving the “Enable” box checked, and I added the following script to my login items to notify me at login if for some reason it isn’t checked:

tell application "System Events"
	if not (UI elements enabled) then
		activate
		display dialog "Enter your password on the next screen to enable \"GUI scripting\""
		set (UI elements enabled) to true
	end if
end tell

Thanks for all your efforts, Adam.

bmose