Clicking a button on a dialog while waiting for something else

Dear Macscripter,

I am trying to get the name of every key in the current keychain, which I have done successfully, all apart from the fact that a dialog pops up from the process “Keychain Scripting” which asks the user to click “Allow” which is button 2. I was trying to use GUI scripting to click this button as below:


tell application "Keychain Scripting"
	set theKeyList to name of every key of current keychain
	repeat with x from 1 to (length of theKeyList)
		
		
		if name of key x of current keychain does not contain "Safari" then
			try
				set thePassword to password of key x of current keychain
				-- setting thePassword needs to happen without waiting for it to end
				tell application "System Events"
					tell process "Keychain Scripting"
						tell window 1
							click button 2
						end tell
					end tell
				end tell
			end try
		end if
	end repeat
end tell

But I have a problem. The line “set theURL to name…” waits for the user to click allow before moving to the next line to click the button with GUI scripting, by which time it is too late. After a search on this forum, I decided to try:


			tell application "System Events"
					tell process "Keychain Scripting"
						set theKeyList to name of every key of current keychain
	repeat with x from 1 to (length of theKeyList)
		
		
		if name of key x of current keychain does not contain "Safari" then
			try
				set thePassword to password of key x of current keychain
				tell window 1
							click button 2
					end tell
					end tell
				end tell
			end try
		end if
	end repeat
end tell

The above doesn’t work because it doesn’t know what “key” means - “Expected class name but found property.”

I’m really hoping that somebody can help me to click this button automatically.

Thanks,

Lambo

Hi Lambo,

some notes:
¢ you’re talking to System Events and System Events doesn’t know what a key is.

¢ The window to confirm (allow or deny) belongs to Security Agent, not to Keychain Scripting

¢ you have a list theKeyList so there is no need to read the keys again for comparing

The following script seems to have the right syntax but it doesn’t work,
I guess, Apple has disabled to script Security Agent for security reasons (but I could be wrong)

tell application "Keychain Scripting" to set theKeyList to name of every key of current keychain
repeat with x from 1 to (length of theKeyList)
	if item x of theKeyList does not contain "Safari" then
		try
			tell application "Keychain Scripting" to set thePassword to password of key x of current keychain
			delay 1
			tell application "System Events"
				if exists process "Security Agent" then
					tell process "Security Agent" to click button 3 of group 1 of window 1
				end if
			end tell
		end try
	end if
end repeat