Adding folder items - update multiple items

Bonsoir

I have this script:

on adding folder items to this_folder after receiving added_items
	 
	 set minutesOld to ((current date) - 30 * minutes)
	
	repeat with i from 1 to the number of items in added_items
		set the_file to item i of added_items
		tell application "Finder"
			if (file the_file exists) then
				try
					do shell script ("/usr/bin/touch " & quoted form of POSIX path of the_file)
					update the_file
				end try
			end if
			
			set ListFiles to every item in folder this_folder
			repeat with eachfile in ListFiles
				if (modification date of eachfile) < minutesOld then
					delete eachfile
				end if
			end repeat
			
		end tell
	end repeat
	
end adding folder items to

Unfortunately, for reasons I do not understand, the above only updates the first item added to the target folder, despite the loop which should mean all added items get updated.

Can anyone test this on their machine? (Or tell me where I have gone wrong!)

Merci

You’ve got the deletion loop inside the ‘touch’ loop, which means that every item in the folder older than ‘minutesOld’ ” including any added items matching that description ” is deleted after the first added item is ‘touched’.

It’s possible that changing the modification date of an item in a folder watched by an ‘adding folder items to’ action could retrigger the action, but I haven’t actually tested this.

Nigel

Thanks. The problem was as you pointed out…

Works fine now:)

on adding folder items to this_folder after receiving added_items
	
	set minutesOld to ((current date) - 30 * minutes)
	
	repeat with i from 1 to the number of items in added_items
		set the_file to item i of added_items
		tell application "Finder"
			if (file the_file exists) then
				try
					do shell script ("/usr/bin/touch " & quoted form of POSIX path of the_file)
					update the_file
				end try
			end if
		end tell
	end repeat
	
	tell application "Finder"
		set ListFiles to every item in folder this_folder
		repeat with eachfile in ListFiles
			if (modification date of eachfile) < minutesOld then
				delete eachfile
			end if
		end repeat
	end tell
	
	
end adding folder items to