Processing files in subfolders

I have the script below that works, but most of the time it takes sooo long for the Finder to create the list of files to process. There are a lot of files to process, ~8,000 total. I was just running the script and after 15min of waiting for it to start the part in Photoshop, I force quit. To get these through I will split up the subfolders into smaller groups (less files per batch).

I’m wondering if there is a better way to code the script so that it does get so hung up. I know Applescript doesn’t have a For statement, but my logic is:

For each Tif files in all subfolders of Source folder
process in Photoshop

on run
	set sourcePath to choose folder with prompt "Please select SOURCE folder:"
	with timeout of 36000 seconds
		tell application "Finder" to set fileList to (files of entire contents of sourcePath whose size > 1 and name ends with ".tif") as alias list
	end timeout
	tell application "Adobe Photoshop CS6"
		activate
		set possibleMode to {bitmap}
		repeat with aFile in fileList
			
			open file (aFile as string)
			set theMode to mode of current document
			--display dialog "Mode: " & theMode & "PossibleMode: " & possibleModes
			if possibleMode does not contain theMode then
				set myOptions to {class:TIFF save options, byte order:IBM PC, image compression:LZW}
				save current document as TIFF in (aFile as string) with options myOptions appending lowercase extension with replacing
			end if
			close current document
			
		end repeat
	end tell
	
	activate
	display dialog "LZW Script is done"
	
end run

Hi. Finder with “Entire Contents” works best for small amounts of files. The shell should be faster and more reliable for anything > 500-ish count.


set theList to (do shell script "find" & space & ((choose folder)'s POSIX path) & space & "-name '*.tif'")'s paragraphs

--this part may not be needed. CS6 may be able to open posix paths
set pathList to {}
repeat with someVar in theList
	set pathList's end to POSIX file someVar
end repeat
pathList

Hi,

if the volume is indexed by Spotlight this is much faster


set sourcePath to quoted form of POSIX path of (choose folder with prompt "Please select SOURCE folder:")
set fileList to paragraphs of (do shell script "mdfind -onlyin " & sourcePath & " 'kMDItemContentType = \"public.tiff\" && kMDItemFSSize > 1'")
tell application "Adobe Photoshop CS6"
	activate
	set possibleMode to {bitmap}
	repeat with aFile in fileList
		open file aFile
		set theMode to mode of current document
		--display dialog "Mode: " & theMode & "PossibleMode: " & possibleModes
		if possibleMode does not contain theMode then
			set myOptions to {class:TIFF save options, byte order:IBM PC, image compression:LZW}
			save current document as TIFF in (aFile as string) with options myOptions appending lowercase extension with replacing
		end if
		close current document
		
	end repeat
end tell

activate
display dialog "LZW Script is done"

I ended up going with Stefan’s solution.

Thank you!