Problem with "Automatic Proxy Image Generator" script

Hi,

We wrote this “Automatic Proxy Image Generator” script.
What the script does is:
When i attach this folder action to a folder named “FullRes_DPX”, it becomes a watch folder, it watches for incoming hires DPX image sequences, then it tells the application shake to resize the files to 720x576 sized images into a folder named “Proxy_DPX”

But there are some problems that i could not resolve:

1-At first we tried to make the resize part of the script with NConvert (command-line utility of XNView), it somehow was not stable. Sometimes it worked, other times it didn’t. I changed the resize application to Shake and it was more stable.
This led me to think that there is a problem in the looping part of the script.

2-When we drag a folder which has images in it, the script creates the new folder in the “Proxy_DPX” folder but it doesn’t resize and copy the images in the dragged folder.

Could you please have a look at the script and point me to the problem areas.
Thank you,

The script is as follows:



on adding folder items to this_folder after receiving these_items
	set AppleScript's text item delimiter's to ":"
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		tell application "Finder"
			set sourcepath1 to container of this_item
			set item_name1 to displayed name of this_item
		end tell
		set sourcepath to sourcepath1 as text
		set item_name to item_name1 as text
		set sourcepath_Unix to the quoted form of the POSIX path of this_item
		set findThis to "FullRes_DPX"
		set replaceWith to "Proxy_DPX"
		set destinationPath to switchText of sourcepath from findThis to replaceWith
		set destinationPath_Unix to the quoted form of the POSIX path of destinationPath
		set dest to (destinationPath_Unix & item_name1)
	if folder of (info for this_item) is true then
		tell application "Finder"
			make new folder at destinationPath with properties {name:item:name}
		end tell
		tell application "System Events"
			attach action to this_item
				using ":Users:makina:Library:Scripts:Folder Action Scripts:Proxy_PAl.scpt"
		end tell
	else
		do shell script ("/Applications/Shake/shake.app/Contents/MacOS/shake " & sourcepath_Unix & " -resize 720 576 -fo " & dest)
	end if
	end repeat
end adding folder items to

to switchText of theText from SearchString to ReplaceString
	set OldDelims to AppleScript's AppleScripts's text item delimiters
	set AppleScript's AppleScript's text item delimiters to SearchString
	set newText to text items of theText
	set AppleScript's AppleScript's text item delimiters to ReplaceString
	set newText to newText as text
	set AppleScript's AppleScript's text item delimiters to OldDelims
	return newText
end switchText


Maybe I have a solution to your problem of not processing images inside folders dropped into your watch folder. I do not know anything about the image conversion stuff you are doing, but the loop looks OK to me.

It looks like your script is attaching a new folder action to folders that are dropped into your initial watch folder. That will not cause the newly attached folder action to be triggered for any files that already exist in the newly attached folder.

If your script is the same as the folder action you are attaching (i.e. the script in your post is Proxy_PAl.scpt), then you could just recurse inside your own adding items to … after receiving … handler. That would look something like this:

tell application "Finder"
	(* For the reasoning behind this try block, see
	http://bbs.applescript.net/viewtopic.php?pid=62379#p62379 *)
	try
		set folder_items to this_item's entire contents as alias list
	on error m
		set folder_items to this_item's entire contents as alias as list
	end try
end tell
if (count of folder_items) is not 0 then ¬
	adding folder items to this_item after receiving folder_items

You could do this instead of attaching the folder action script to this_item. Or if you expect that files might be dropped into this_item (ever after it has been moved into your watched folder), later you can attach the script and recurse to process the already existing items.

If the script in your post is not the same as the script you are attaching, then you would have to do something slightly different involving load script from the Standard Additions OSAX (compiled, but untested):

if (count of folder_items) is not 0 then
	set the_script to load script file "path_to_script"
	tell the_script to adding folder items to this_item after receiving folder_items
end if