Why does this take twice to get result?

Hullo list,
I have a script that I drop a folder with around 2,000 files in it. Out of that 2,000 about 200 of them are Quark docs. I need to get a list of the Quark docs so I can open them and save EPS files. What I have works, but it usually takes dropping the folder twice before it gets all the files needed. I copied the part of the script that gets the files and did a quick test. I am posting that script here. My question is, why can’t it get the needed info the first time it runs?

on open x
	set myFolder to x as alias
	set myList to myGetList(myFolder)
	try
		if myList is {} then
			display dialog "nothing here"
		else
			set myCount to count of myList
			display dialog myCount
		end if
	end try
end open

on myGetList(myFolder)
	with timeout of 500 seconds
		tell application "Finder"
			set x to every file of myFolder
			set myList to {}
			repeat with i from 1 to count of x
				set myFile to item i of x
				try
					if file type of myFile is "xprj" then
						set myFile to myFile as text
						set end of myList to myFile as text
					end if
				end try
			end repeat
		end tell
	end timeout
	return myList
end myGetList

Thanx,
mike helbert

I don’t know why it takes two tries, but I do notice that you could have said:

set x to every file of myFolder whose file type is "xprj"

and saved yourself the repeat back through the files item by item in your handler.

It may be that your script takes so long that it’s timing out or that there’s an
error you’re ignoring in your try statement.

You don’t appear to mention whether you get a partial result or a fat zero first time around, Mike. In any case, it might be worth getting Finder to update the folder before checking for files - especially with so many involved. And if you were wondering how you might convert filtered Finder references into a list of strings, something like this might do the trick for you:

to open myFolder
	set myList to getList(myFolder)
	display dialog "Files found: " & (count myList)
	-- do something with myList
end open

to getList(f)
	set tid to text item delimiters
	set text item delimiters to return
	tell application "Finder"
		update folder f
		with timeout of 500 seconds
			set l to (folder f's files whose file type is "xprj") as string
		end timeout
	end tell
	set text item delimiters to tid
	if (count l) is 0 then return {}
	l's paragraphs
end getList

:slight_smile: