ow can I tell a script to pause until a folder meets conditions?

Hi,
I would like a script to pause until a folder has equal numbers of files with jpg and crw extension. I figued out how to do this:
on idle
tell application “Finder”
set jpgcount to the count of (files of folder “Disk:Business:Workflows:WorkflowScripts:ProcessedImagesTemp:” whose name extension is “jpg”)
set rawcount to the count of (files of folder “Disk:Business:Workflows:WorkflowScripts:ProcessedImagesTemp:” whose name extension is “crw”)
if jpgcount = rawcount then
display dialog jpgcount
end if
end tell
return 5
end idle

The problem is that it only works when I save this as a stay open application and not as part of a much bigger script. So how can I tell a script to pause until that folder has equal numbers of jpeg and crw files?

thank you so much
Karo

karoddo,

“on idle” handlers always only work in stay-open applets, since they need to keep running. To do this in a regular script, you’d have to use a repeat, delay loop, which uses somewhat more processor time, although I believe it is much less processor-intensive than in early AppleScript. I’ve done this without noticing any slowed-down system-response issues on a 500 MHz PowerBook G4, and even older Macs. So, the code could look something like:


set waitBetweenChecks to 5
-- pick a reasonable number of seconds to wait between checks

set countsAreEqual to false

repeat until countsAreEqual
	tell application "Finder"
		set jpgcount to the count of (files of folder "Disk:Business:Workflows:WorkflowScripts:ProcessedImagesTemp:" whose name extension is "jpg")
		set rawcount to the count of (files of folder "Disk:Business:Workflows:WorkflowScripts:ProcessedImagesTemp:" whose name extension is "crw")
	end tell
	
	if jpgcount = rawcount then
		set countsAreEqual to true
	else
		delay waitBetweenChecks
	end if
end repeat