Applescript Photoshop question

Below is my script. It’s function to to crawl through a directory of photos… looking for JPGs that are over a resolution of 100dpi. When it finds one larger, it resizes the image to 100dpi and saves the file.

My question is, the instruction “close saving yes” in the photoshop loop doesn’t ALWAYS work. Sometimes I get a dialog prompting me for the save. Can anyone think when or why this would occur. Out of 700 folders I just processed… there’s maybe 10 that didn’t work. These JPGs are the result of a JPG image being attached to a CRM order system, so they should all be saved in the same manner.

thanks
david


tell application "Finder"
	--activate
	
	set myDirectory to folder "zTestFiles"
	set aOrderList to the name of every folder in myDirectory
	set orderItems to number of items in aOrderList
	set n to 0
	set d to 0
	repeat with i from 1 to orderItems
		set thisFolder to (myDirectory as string) & item i of aOrderList & ":"
		try
			set aGraphicsList to (the name of every file in (folder (item i of aOrderList) in myDirectory) whose name ends with ".jpg")
			set graphicItems to number of items in aGraphicsList
			
			repeat with j from 1 to graphicItems
				--activate
				tell application "Adobe Photoshop CS3"
					--activate
					try
						open file (thisFolder & item j of aGraphicsList) showing dialogs never
						tell document 1
							--display dialog "opened: " & (item j of aGraphicsList as string) & "    " & resolution
							set myProperties to properties
							if resolution > 100 then
								resize image resolution (100 as number) resample method bicubic
								--display dialog "resized successfully"
								close saving yes
								--display dialog "closed successfully"
							else
								close
								--display dialog "deleting folder: " & thisFolder
								tell application "Finder"
									delete folder named thisFolder
									set d to d + 1
								end tell
								--display dialog "no resize   " & resolution as string
							end if
						end tell
					end try
				end tell
			end repeat
		end try
		set n to n + 1
	end repeat
	display dialog "done - processed " & n & " folders.  Deleted " & d & " folders"
end tell

Here’s the modifications I use in my CS resize routine

tell application "Adobe Photoshop CS2"
	set display dialogs to never
	tell settings
		set oldPrev to image previews
		set oldMac to Mac OS thumbnail
		set oldWin to Windows thumbnail
		set oldHistory to number of history states
		set properties to {image previews:no, Mac OS thumbnail:false, Windows thumbnail:false, number of history states:1}
	end tell
	
	(*
	
	your code
	
	*)
	
	
	tell settings
		set properties to {image previews:oldPrev, Mac OS thumbnail:oldMac, Windows thumbnail:oldWin, number of history states:oldHistory}
	end tell
end tell

I would expect it to work in CS3