Folder Action: "Delay until images loaded" possible?

Question
Is there a command that can force an action to wait until ALL of the images are copied into a folder that has a folder action attached to it?

Explanation
I have a very simple folder action which simply takes the files that are dropped into it and runs a photoshop script that I have. The problem is, the main files that I use to drop into the folder are RAW files. These RAW files have very small files that come along with them automatically (.xmp) which essentially passes information to photoshop about how to modify the RAW image. I keep all of my RAW files on an external hard drive, which means, there is some elapse time for how long it takes these files to be copied over.

If the RAW file is copied over without the XMP file, meaning, the folder reads the first of ten images as soon as it is copied into the folder, but doesnt wait for its associated XMP file to be copied, the photo comes out completely messed up. The way I have jerry rigged a solution is by putting a “delay” on the folder. This works perfectly. When all of the files are copied over it runs the script beautifully. The only problem is, some times it may only take 3 seconds to copy a file over, and other times it may take a few minutes. A “Delay” is just impractical.

Any ideas on how best to remedy this? Is there such a command as “Once all Files Are Copied then…”

-i

on adding folder items to this_folder after receiving these_items
	delay 20.0
	repeat with an_item in these_items
		set ext to name extension of (info for an_item)
		if ext is not equal to "xmp" then
			tell application "Adobe Photoshop CS2"
				activate
				open an_item
				do action "landscape or portrait" from "process for screen"
			end tell
		end if
	end repeat
end adding folder items to

I use this (the length of the waits is arbitrary - I use 3 seconds for downloads):


set myFolder to (choose folder) as alias -- use the path to the folder that's loading
set firstSize to size of (info for myFolder) --get initial size
delay 3 --wait 3 seconds
set newSize to size of (info for myFolder) --get a newer size, bigger
repeat while newSize ≠ firstSize --if they don't equal, loop until they do
	set firstSize to newSize --new base size
	delay 3 --wait three seconds
	set newSize to size of (info for myFolder) --get a newer size
end repeat --once the sizes match, the transfer is complete

BTW, you can use that as a handler too:

on folderReady(tFolder)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 3 --wait 3 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady

if folderReady(a folder ref) then
-- press on
end if

Adam,

thanks for the response.

I just attached the action below to the folder and nothing happens when I put files into it. Maybe I am just not understanding your code or what exaclty is is doing. It doesn’t seem to activate anything.

What am I not getting here?

Also, I use “path to me” in the hopes that I can retain the “modular” aspect of folder actions. Is this not possible with your solution?

-i

on folderReady(tFolder)
	display dialog (path to me)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 3 --wait 3 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady

display dialog (path to me)

if folderReady(path to me) then
	display dialog "this works"
end if

Adam,

since I can’t figure this out, is there just a different handler where I select mulitple images and run a script with a handler that goes soemthing like this

with these_selected_images do this

I have been searching through the forums for the past 3 hours JUST for any script that simply allows me to click on an image file and run a script and can’t find anything. I can forget about transfering the files to a folder on a different drive, I just want to be able to select specific images and run a script that applies to them. Is this not possible? I see all of these “on run” handlers, but that will cause the same problems I have had before.

I seriously thought that just getting AS to point to a photoshop action would be the easiest thing, but I can’t even seem to get that to work. Argh! :frowning:

-i

My answer was intended to replace the “delay 20” in your script.

Try this: (I can’t test it, and your photoshop block is commented out because I don’t have it - put it back in). If it doesn’t do what you had in mind, then I’ve misinterpreted what you wanted.

on adding folder items to this_folder after receiving these_items
	if folderReady(this_folder) then
		repeat with an_item in these_items
			set ext to name extension of (info for an_item)
			if ext is not equal to "xmp" then
				(*tell application "Adobe Photoshop CS2"
				activate
				open an_item
				do action "landscape or portrait" from "process for screen"
			end tell*)
			end if
		end repeat
	end if
end adding folder items to

on folderReady(tFolder)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 3 --wait 3 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady

Adam,

as I thought, you were perfectly on target and I was perfectly moronic.

The script pasted below does exactly what I was hoping for. Thank you! As a side, is there a handler instead of the folder action handler that can capture image files that you have highlighted?

Thanks again!

on adding folder items to this_folder after receiving these_items
	if folderReady(this_folder) then
		repeat with an_item in these_items
			set ext to name extension of (info for an_item)
			if ext is not equal to "xmp" then
				--display dialog ext
				tell application "Adobe Photoshop CS2"
					activate
					open an_item
					do action "For Print and Screen" from "Process Images"
				end tell
			end if
		end repeat
	end if
	tell application "Finder"
		activate
		display dialog "FILES RESIZED" & return & "Check desktop for folders:" & return & "->Photos for Email<-" & return & "->Photos For Winkflash<-" buttons {"Ok"} with icon note
	end tell
end adding folder items to

on folderReady(tFolder)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 3 --wait 3 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady
tell application "Finder" to set S to (get selection)

This returns a list of Finder references to the files selected (highlighted) in the frontmost Finder window. Note that even if only one item is selected (file or folder, doesn’t matter) it is still one item in a list.

If what you want to do is automate moving them to your folder with the action, do this:

tell application "Finder"
	set S to (get selection) -- Finder window in front with selected files
	set F to choose folder -- the target of the move
	repeat with I in S
		duplicate contents of I to F
	end repeat
end tell

Talk about revisiting an old post eh? Sorry to bother again, but for some reason using the script is no longer working. My folder scrips got trashed somehow, so I applied this one again to my folder and I don’t see it working at all. Am i forgetting something for a folder script? I have done the following:

Saved the script as a .app
target folder > right click > “enable folder actions”
target folder ? right click > “configure folder actions”
browsed to and selected my newly created .app to run.

I have also since upgraded photoshop, my os to leopard and my action names have changed, but that was a simple cut and paste. Am I missing something? Do I need to flick some big hidden switch somewhere that I forgot about? Sorry for so many lame questions, it’s just that script was working so fantastically and the alternative I have set up to replace it since it doesn’t work anymore is just a really inefficient way of doing it.

on adding folder items to this_folder after receiving these_items
	if folderReady(this_folder) then
		repeat with an_item in these_items
			set ext to name extension of (info for an_item)
			if ext is not equal to "xmp" then
				--display dialog ext
				tell application "Adobe Photoshop CS3"
					activate
					open an_item
					do action "landscape or portrait" from "process for print, email, thumbs"
				end tell
			end if
		end repeat
	end if
	tell application "Finder"
		activate
		display dialog "FILES RESIZED" & return & "Check desktop for folders:" & return & "->Photos for Email<-" & return & "->Photos For Winkflash<-" buttons {"Ok"} with icon note
	end tell
end adding folder items to

on folderReady(tFolder)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 3 --wait 3 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady