AppleScript AI like behavior? need help.

Here’s the situation, I’m currently trying to make a script which can capture buttons on a particular interface.
For example, in an installer application, after the installer window is opened, the script should be able to know all the available buttons in that current window tab (e.g. continue, previous, next, etc…) The script must then try to match the available buttons to a set of predefined buttons which it is allowed to click.

Here’s what I have in mind, first, it should read identify all available gui elements (buttons, textboxes, etc…)
Then, it should be able to click buttons that are prespecified, which may be in random order.

If I run an application with a continue button, the script must be able to detect the continue button and click it. On the other hand, if there is an application with a Next button, it should also be able to see that and click it without me modifying the code.

Help would be very much appreciated.

thanks

is this possible to do?
i need help. thanks

Hi,

you can do that by testing the existence of certain UI elements


tell application "System Events"
	tell process "foo"
		if exists button "bar1" then
			-- do something
		else if exists button "bar2" then
			-- do something else
		end if
	end tell
end tell

is it possible if i put it in a loop? for example:


				repeat while exists application "Installer"
					if exists button "Continue" of sheet 1 of window 1 then
						click button "Continue" of sheet 1 of window 1
					else if exists button "Continue" of window 1 then
						click button "Continue" of window 1
					else if exists button "Agree" of sheet 1 of window 1 then
						click button "Agree" of sheet 1 of window 1
					else if exists button "Install" of window 1 then
						click button "Install" of window 1
					else if exists button "Close" of window 1 then
						click button "Close" of window 1
					end if
				end repeat

it doesnt work for me, probably because the syntax is wrong?

Sytem Events doesn’t know “application”, you should check process “Installer”

I doubt you can write an universal script which catches all cases during an installation process

I used repeat until bool = true instead.

anyways, how about if i ask it to wait for the security agent dialog to exist then type in the password?

I tried using the snippet below in a loop but it doesnt work:


if exists window 1 of process "SecurityAgent" then
keystroke "password"
-- i also tried tell window 1 of process "SecurityAgent" to set value of text field 1 to "password"
keystroke return
end if

Where did i go wrong?

tell window "Authenticate" of process "SecurityAgent"
	tell group 1
		set value of text field 1 to "myName"
		set value of text field 2 to "myPassword"
	end tell
	click button "OK" of group 2
end tell

it doesnt seem to capture it. I noticed that the security agent dialog does not show any window titles.
If i use the ui browser, AXWindow=“”.
Is there any other way to capture the event?

then try window 1 instead.
Maybe Apple changed something in Snow Leopard. The script works in Leopard