Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jester831

macrumors newbie
Original poster
Aug 16, 2008
5
0
I am working to make a script to interact with flash and in doing so I am forced to deal with non-existent objects. That is, at any point in time the object may or may not exist. I started out by writing a very rough conceptual program to make sure I could successfully timeout until objects exist and then click on them and through some effort I got that to work. However, I want modularity in the program and need to find a way to pass non-existent objects into a function that waits for the object to exist.

An example of what I mean -

This is the code that works:
tell application "System Events"
repeat
if UI element 1 of scroll area 1 of group 2 of window "Window-Name" of application process "Safari" exists then
exit repeat
else
delay 1
end if
end repeat
end tell

This is the code that does not work - I get the error that the passed object does not exist
Code:
on LoadObject(targetObject, targetName, loadThreshold)
	set loadTime to 0
	log_event("Loading " & targetName & "... " & loadTime)
	repeat with loadTime from 0 to loadThreshold
		try
			if targetObject exists then
				log_event("Loaded " & targetName)
				return true
			else
				delay 1
				log_event("Loading " & targetName & "... " & loadTime)
			end if
		end try
	end repeat
	log_event("Failed to load " & targetName)
	return false
end LoadObject

Furthermore, in this code, I get the error that the object does not exist and cannot pass it
tell application "System Events"
set theElement to UI element 1 of scroll area 1 of group 2 of window "Window-Name" of application process "Safari"
end tell

Any tips would be much appreciated!
 
Maybe in the first chunk of code you should put a try/end try there as well, so that you're not sending a bad object to the function. Also "missing value" is AppleScript's way of testing for null so you could try that too.
 
well, doing a try block somewhat defeats the purpose - if the object exists, there's no point in waiting for it to exist. I want to send a bad object with the expectation that it will become a good object and return true within a timeframe or return false.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.