Modification Date Filter (Applescript Scriptlet Help)

Greetings and salutations. Long time Reader, first time poster.

I have a television capture setup on my mac that outputs to .mpg. I have been successful in creating a workflow that converts the files to h.264, adds them to iTunes, tags them as TV Shows and syncs with the ipod. However, I would like to create an applescript inside of this workflow that accepts the .mpg movies early on as (Files/Folders), examines them, filters out any that have a modification date that is newer than the last five minutes and then passes the results onto the next workflow action. This will allow the workflow to ignore the movie files that are actively being processed by the capture software and thus avoiding an incomplete/corrupted movie to move through the rest of the workflow.

My own attempts (based on similar scripting by another author) has not been successful so far. My work so far is as follows:

on run {input, parameters}
	tell application "Finder"
		set tvShows to input
		set movieCount to the count of files in tvShows
		if movieCount > 0 then
			set minutesAgo to ((current date) - (5 * minutes))
			set movieFiles to the name of every file of tvShows
			set tvShows to tvShows as string
			repeat with i from 1 to movieCount
				set movieFile to item i of movieFiles
				set moviePath to {tvShows & movieFile} as string
				set modDate to the modification date of item moviePath
				if modDate - minutesAgo then
					set input to moviePath
				end if
			end repeat
		end if
	end tell
	return input
end run

Any help is greatly appreciated. Thank you.

Hi and welcome.

According your code the input is just one folder.
The main problem is, the handler variable input is always a list, so you have to reference an item of this list.

in Leopard this might be sufficient

on run {input, parameters}
	tell application "Finder" to return (items of item 1 of input whose modification date < ((current date) - 300)) as alias list
end run

it passes all items of the folder whose modification date is older than 5 minutes ago

in Tiger you get an error message using alias list, if there is only one item,
so a little error handling must be included

on run {input, parameters}
	tell application "Finder"
		set filteredItems to (items of item 1 of input whose modification date < ((current date) - 300))
			return filteredItems as alias list
		on error
			return filteredItems as alias as list
		end try
	end tell
end run

Thanks for your reply Stefan.

I believe that those scripts are almost what I need. However after an initial test, I saw that no items were getting through the filter. After re-reading your post I found that I misrepresented myself by my misguided scripting attempt. The action that will proceed the date modification filter script is a “Find Finder Items” action that returns the files, but no encapsulating folder.

any suggestion based on this development?

I really can’t believe all that I learned out of just reading those two scripts you posted. I’m actually enjoying the learning process of all this and plan to buy an applescript book this afternoon.

ok, then try this

on run {input, parameters}
	set output to {}
	repeat with oneFile in input
		if modification date of (info for oneFile) < ((current date) - 300) then set end of output to contents of oneFile
	end repeat
	return output
end run

That did the trick.

It’s also going to help me create similar filters I have in mind for other projects.

Thank You