how to ignore errors

I have a script

tell application "QuickTime Player"
	set current time of document "Promised Land" to 4000000
	set current time of document "U.S. Blues" to 1000000
	set current time of document "Glendale Train" to 300000
end tell

but if US Blues is not open, an error ocures and Glendale Train is not set.
Putting the whole routine inside one try…end try has the same effect. Hence my current script:

tell application "QuickTime Player"
	try
		set current time of document "Promised Land" to 4000000
	end try
	try
		set current time of document "U.S. Blues" to 1000000
	end try
	try
		set current time of document "Glendale Train" to 300000
	end try
end tell

Is there a cleaner/neater/easier way to do this? A “ignore errors, go to next line”…“end ignore errors” construction?

I’m not asking for a clever feature of QuickTime Player, but about AppleScript error handling.

Thank you.

Hi,

there is no other way as wrapping each entry in a try block.
But an alternative is to check the existence of the document.
You can use also a list e.g.


property docList : {"Promised Land", "U.S. Blues", "Glendale Train"}
property valueList : {4000000, 1000000, 300000}

tell application "QuickTime Player"
	repeat with i from 1 to count docList
		set doc to item i of docList
		if exists document doc then set current time of document doc to item i of valueList
	end repeat
end tell

oooh … I like that.

Thanks for the tip.

If I could ask a follow up question,

What is the difference between

property docList : {"Promised Land", "U.S. Blues", "Glendale Train"}

and

set docList to {"Promised Land", "U.S. Blues", "Glendale Train"}

a property defines a value at compile time and is visible globally
the set command defines a value at run time and is visible locally

Thank you.