Parsing folders to find .tif files with alpha channels

Hi there,
I’m using the following script to find and modify any .tif files that contain an alpha channel (filemaker pro’s import function crashes when it encounters an alpha channel). Thing is, when I run the script and point it to a folder on the file server, the second step (get every item) takes too long, and the script times out. Is there a more efficient way to get images, or should I set a larger timeout and find something to do while it works?


set This_Folder to (choose folder)
tell application "Finder" to set these_items to get every item of entire contents of This_Folder whose kind is "Adobe Photoshop TIFF file"
repeat with i from 1 to number of items in these_items
	set this_item to item i of these_items
	
	set thisImage to POSIX path of (this_item as string)
	set quotedImage to quoted form of thisImage
	set exifdata to do shell script "exiftool -a -g1 " & quotedImage
	set itsgotanalphachannel to (exifdata contains "Alpha Channels Names            : Transparency, Alpha 1")
	
	if itsgotanalphachannel then
		log "it's got an alpha channel"
		my deletealpha(thisImage)
	end if
	
end repeat

on deletealpha(thisImage)
	tell application "Adobe Photoshop CS5.1"
		set mydocument to open file (thisImage as string)
		tell current document
			set mybadchannels to every channel whose kind is not component channel
			delete mybadchannels
			save in (thisImage as string) as TIFF with options {transparency:true, save alpha channels:false}
		end tell
	end tell
end deletealpha

Model: iMac
AppleScript: 2.1.2
Browser: Firefox 7.0.1
Operating System: Mac OS X (10.6)

You could try and relace:

With this shell script:

set This_Folder to (choose folder)
set fPath to POSIX path of This_Folder
set these_items to paragraphs of (do shell script "ls " & quoted form of fPath & " | grep -i .tif")

It should be quicker!

This will, of course, select every file with .tif in its filename and will not take into account if it is a Photoshop tiff or not.

Thanks, can I modify the shell script to list contents of all subfolders?

Yes.
Change the last line to:-

set these_items to paragraphs of (do shell script "ls -R " & quoted form of fPath & " | grep -i .tif")

(Adding the -R (recursive) after ls)