Repeat / select first file script help

Hi Guys,

With the kind help of posters to this site I have the following script -


on adding folder items to this_folder after receiving theFiles
	set thepath to ((path to desktop as text) & "GC test receive:")
	tell application "Finder" to set CF to (count files in folder "GC test" of desktop)
	if CF = 4 then
		repeat with oneitem in theFiles
			set fileName to name of (info for oneitem)
			tell application "GraphicConverter"
				activate
				open oneitem
				tell window 1
					save in (thepath & fileName) as JPEG
					close
				end tell
			end tell
		end repeat
		tell application "Finder" to delete theFiles
	end if
end adding folder items to

The hope is that the script waits for four files to be added to a folder (they are coming from a camera so will have a different name each time) and then opens and saves each one using Graphic converter. This script certainly works on the last file added to the folder once there are four there but it doesn’t carry on and process the remaining 3 files.
Does anyone know how to script a repeat for this or is there a way to select the first file from a folder and process it and then select the second file and so on? I’m very stuck with how to script processes for files whose names are not known.

Any help very appreciated,
Thanks guys.

JM

Sorry, what’s the purpose to wait for 4 files, if the filename is always different?
Couldn’t the folder action process file by file, the code would be much cleaner


on adding folder items to this_folder after receiving theFiles
	set thepath to ((path to desktop as text) & "GC test receive:")
	repeat with oneitem in theFiles
		set fileName to name of (info for oneitem)
		tell application "GraphicConverter"
			open oneitem
			tell window 1
				save in (thepath & fileName) as JPEG
				close
			end tell
		end tell
	end repeat
	tell application "Finder" to delete theFiles
end adding folder items to

Hi Stefan,

The problem is that the files are coming from a camera which is taking 4 photos in succession with just the time taken to download the file from the camera (about a second) in between shots. This is too fast for the script to keep up. It works for the first file but then gets stuck when the next files start backing up. I wanted it to wait for the four files first so it would then have time to run through the processes before the next shots are taken.

Thanks,

JM.

try this


on adding folder items to this_folder after receiving theFiles
	set thepath to ((path to desktop as text) & "GC test receive:")
	tell application "Finder" to set CF to count (get files of this_folder)
	if CF = 4 then
		repeat with oneitem in theFiles
			set fileName to name of (info for oneitem)
			tell application "GraphicConverter"
				open oneitem
				tell window 1
					save in (thepath & fileName) as JPEG
					close
				end tell
			end tell
		end repeat
		tell application "Finder" to delete theFiles
	end if
end adding folder items to

No joy I’m afraid, waits for the four files but still only processes the last file received and leaves the remaining three.

Thanks,
JM

sorry, I missed something


on adding folder items to this_folder after receiving theFiles
	set thepath to ((path to desktop as text) & "GC test receive:")
	tell application "Finder" to tell (get files of this_folder) to set {CF, fourFiles} to {count it, it}
	if CF = 4 then
		repeat with oneitem in fourFiles
			set fileName to name of (info for oneitem as alias)
			tell application "GraphicConverter"
				open (oneitem as alias)
				tell window 1
					save in (thepath & fileName) as JPEG
					close
				end tell
			end tell
		end repeat
		tell application "Finder" to delete fourFiles
	end if
end adding folder items to

Thats it, brilliant!

Thanks Stefan.

JM