Looping Folder Action Problem

I have cobbled together a Folder Action script which, though not elegant, initially worked at doing what I intended it to do - on having an image file from a tethered camera downloaded to it, the script activates, opening the file in Photoshop, applying an action which adjusts the image then prints it to a specific printer, then saves the file back to the watch folder and closes it.

Where I’m having problems is that when multiple images are taken with the camera in rapid succession the script apparently can’t keep up and only processes the first image, ignoring the rest. What I think the script needs is a looping sequence that will move the processed file out of the watch folder to a designated folder, then tell Photoshop to continue to look back through the watch folder and open each remaining file until all have been processed and moved. I’ve tried to script the move sequence at the end but it doesn’t seem to work.

I’ve looked through the many helpful posts on MacScripter but haven’t figured out how the loop needs to be scripted and where it needs to be inserted in the existing script. Any help would be greatly appreciated as this has me at a standstill.

Thanks,

Kevin

Here’s my script so far:

-- Folder Action that works on a watch folder and activates when an image is downloaded to it from a tethered camera
on adding folder items to thisFolder after receiving thisItem
-- Script opens the image file in Photoshop, runs an action that adjusts gamma and prints the image to a specified printer then saves and closes file back to the watch folder 
	tell application "Adobe Photoshop CS4"
		activate
		open thisItem
		tell application "Adobe Photoshop CS4"
			do action "Photo Process" from "Photo Actions"
		end tell
	end tell
	tell application "System Events"
		activate
		tell process "Photoshop"
			set frontmost to true
			keystroke "p" using {command down}
			key code 36
			delay 2
			key code 36
		end tell
	end tell
-- After file has been processed, printed and saved this part of the script moves the processed file from the watch folder to a folder called "Processed_Images". Unfortunately this part does not work.
	tell application "Finder"
		move thisItem to (folder "Volumes:Macintosh HD:Processed_Images")
	end tell

end adding folder items to

Model: MacBook Pro 2.66 OSX10.6.4
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

First things first. Your folder action definition is wrong. See here. Basically you’ll see that you are passed a list of items, not one item. Since you get a list you use a repeat loop to cycle through the list and process each file in the list. You’re not doing that. You need to be doing this…

on adding folder items to thisFolder after receiving theItems
	repeat with i from 1 to count of theItems
		set thisItem to item i of theItems
		-- do something with thisItem
	end repeat
end adding folder items to

So that may be why it’s not working. However, you could still be right that folder actions do not work reliably because they are not reliable. I never use folder actions because of that. What you may want to do instead is create a normal script. After getting the images from your camera and placing them in a certain folder, you run your script which processes all the files in that folder. Something like this would work…

set cameraFolder to "Volumes:Macintosh HD:Camera_Images"
set processedFolder to "Volumes:Macintosh HD:Processed_Images"

tell application "Finder"
	set filesList to (files of folder cameraFolder) as alias list
end tell

repeat with i from 1 to count of filesList
	set thisItem to item i of filesList
	-- do something with thisItem
	-- move thisItem to folder processedFolder
end repeat