Automate Button Clicks with AppleScript Failing

I’m trying to use AppleScript to automate the launching and selecting of files for a tool called CheckMate (a type of XML file validation tool for translators, but not really important for the purposes of this posting).

I can get AS to launch the app, but after CheckMate flashes up for a split second, focus jumps back to the AS editor and none of the steps after launching the app are carried out.

I need AppleScript to click on a button marked Session… which will open a new window where I need to then select “Add” and then have the script exit so I can select the file I need and proceed with using CheckMate.

Here is what I have so far:

tell application "CheckMate" to activate
tell application "System Events"
	tell process "CheckMate"
		click button "Session..." of window "Untitled - CheckMate"
		delay 1
		click button "Add..." of window "Session Settings"
	end tell
end tell

Not only does this fail to click any of the buttons, but it also hangs the script after CheckMate launches. I close CheckMate, but the script just hangs there for 3-4 minutes before it finally ends and I can try having another go.

I’ve read up all I can on button clicking and it seems very straight forward, so I don’t see where my error is.

I’ve tried using just three periods after “Session” and “Add” (“Session…”, “Add…”) as well as an actual ellipsis character (option key + semicolon), but this doesn’t seem to have helped any.

Can anyone point out where I’ve come off the rails?

Thanks

Hi,

i recommend to wait for the second window in conjunction with some timeout code


tell application "CheckMate" to activate
tell application "System Events"
	tell process "CheckMate"
		click button "Session..." of window "Untitled - CheckMate"
		set timeoutValue to 20 -- time out after 10 seconds
		repeat until (exists window "Session Settings") or (timeoutValue is 0)
			delay 0.5
			set timeoutValue to timeoutValue - 1
		end repeat
		if timeoutValue is 0 then
			-- do error handling
		else
			click button "Add..." of window "Session Settings"
		end if
	end tell
end tell


Thanks, Stefan, I appreciate your help.

Unfortunately, after CheckMate launches it does as before - it flashes up for a second, focus goes back to the AppleScript editor and then nothing.

I have to close CheckMate, but the AppleScript just hangs on for about 3-4 minutes and then stops running.

I’m stumped. It must be something to do with CheckMate.