GUI Scripting Question

After going through some excellent articles on GUI scripting, I decided to give it a try. I have an application which I use to upload files to a server. This application has a Menu bar item called Export which has many options.
When I click an option, a sheet opens where I input file name in a textfield and then click the Upload button on this sheet. A new sheet with progress bar appears. After the upload finishes, another sheet opens which has a Done button. After clicking the Done button, I repeat the steps mentioned earlier to upload again.

I have come up with a little GUI script that works till the point where I can get it to start the Upload process.
I want to enhance this script such that it can run in a repeat loop given a list of file-names to upload.

Here is my attempt:

try
	-- bring the target application to the front
	set fileNames to {"file1", "file2", "file3", "file4"}
	set myListCount to count of items in fileNames
	tell application "XYZ"
		activate
	end tell
	tell application "System Events"
		tell process "XYZ"
			repeat with theItem in fileNames
				tell menu bar 1
					tell menu bar item "Export"
						tell menu "Export"
							keystroke "T" using {shift down, command down}
							tell sheet 1 of window 1
								keystroke theItem
							end tell
						end tell
					end tell
				end tell
				delay 3
				click button "Upload" of sheet 1 of window 1
-- Code to click Done button on the last sheet and resume upload of next file in List
			end repeat
		end tell
	end tell
	return true
on error error_message
	return false
end try

I want to automate clicking of the Done and then continue the file upload process with the next file in the List. How can I achieve this? How do I make my script aware that the Done button is ready to be clicked and resume the Upload process with next file in the list.

Hello!

Could you please share links to the excellent articles?

Thanks! :slight_smile:

http://www.macosxautomation.com/applescript/uiscripting/index.html
http://tidbits.com/static/html/TidBITS-670.html

Hello!

Your references are good, here is one I stumbled over, by Kai Edwards. It provides a superb technique for revealing info from Ui elements!

Here it is.

An Introduction to Extracting Elements & Properties from Objects.

For the record, I think you lack the “wait until sheet becomes visible” trick, look for that under UI Scripting posts here.

The wizards uses that! I think I saw it last in a post by Nigel Garvey for either Preview, or save as PDF.

Hi,

it’s not necessary to address then menu item if you just use the keyboard shortcut.


try
	-- bring the target application to the front
	set fileNames to {"file1", "file2", "file3", "file4"}
	set myListCount to count of items in fileNames
	tell application "XYZ"
		activate
	end tell
	tell application "System Events"
		tell process "XYZ"
			repeat with theItem in fileNames
				
				keystroke "T" using {command down} -- same as keystroke "t" using {shift down, command down}
				repeat until exists sheet 1 of window 1
					delay 0.2
				end repeat
				tell sheet 1 of window 1
					keystroke theItem
					delay 3
					click button "Upload"
				end tell
				-- Code to click Done button on the last sheet and resume upload of next file in List
			end repeat
		end tell
	end tell
	return true
on error error_message
	return false
end try

Is there any UI indicator to press the Done button (visible, enabled, title change)?

McUsr, thanks for that link. It’s a neat mini-review - gave me an idea right away, too.

Glad I could help Alastor. :slight_smile:

Looking above I see StefanK, and The Trick!

Here is another one: its the old pages of gui scripting of apple, altough they are from the wayback machine, you can still navigate between them!

You do so, by editing the url field in the wayback machine, which is in a frame around the webpage, there are pages 01-04.html!

Apple - Software - AppleScript - GUI Scripting

I got the loop thing working by adding this small statement:


-- Code to click Done button on the last sheet and resume upload of next file in List
repeat until exists button "Done" of sheet 1 of window 1
					--- do nothing
end repeat
delay 2
click button "Done" of sheet 1 of window 1

Faster


	-- Code to click Done button on the last sheet and resume upload of next file in List
	repeat until exists button "Done" of sheet 1 of window 1
		delay 0.5
	end repeat
	click button "Done" of sheet 1 of window 1


Kai Edwards was a prolific and very talented scripter (I have 66 of his gems in my files) and a good Internet friend of Nigel Garvey’s and mine. The article was the last one he wrote with some difficulty because he died of a very painful form of cancer soon after it was finished and I published it. He had frequent very spirited and good-natured jousts with Nigel on these forums from which the rest of us learned a lot. I miss him and I’m sure Nigel does too.