Simple Script - but why can't I get it to work?

I’ve been working at this for the last two hours - there must be something I’m missing here, but I can’t seem to figure why this doesn’t seem to work. All I’m tring to do is return a list of files in specified folder that have been updated (based on modification date) in the last two weeks.

Here’s where I’m at

set aFortnightAgo to the (current date) - 14 * days
tell application "Finder"
	set compList to get every item in folder "designated folder"
	set manualUpdate to {}
	repeat with newUpdated in compList
		set theDate to modification date of (newUpdated as alias)
		if theDate is greater than aFortnightAgo then
			set updatedRecently to the name of newUpdated
		end if
		set manualUpdate to manualUpdate & updatedRecently
	end repeat
end tell

Despite the fact that several files in my desiginated folder have been updated as recently as earlier today, this script fails to return any of those files. Its really frustrating me b/c when I take on of those files and test it indivually with a dumbed down script like this

set aFortnightAgo to the (current date) - 14 * days
tell application "Finder"
	set theDate to modification date of file "designated file thats been recently updated"
	if theDate is greater than aFortnightAgo then
		beep
	end if
end tell

everything works as it should. Clearly something goes wrong when I run it though the repeat, but I don’t know what. Sorry if this seems like an obvious one, but any help with this would be greatly appreciated!

Hi,

your variable updatedRecently won’t be defined if the first item doesn’t match the condition
Try this:


set aFortnightAgo to the (current date) - 14 * days
tell application "Finder"
	set compList to get every item in folder "designated folder"
	set manualUpdate to {}
	repeat with newUpdated in compList
		set theDate to modification date of newUpdated
		if theDate is greater than aFortnightAgo then
			set end of manualUpdate to name of newUpdated
		end if
	end repeat
end tell

Note: inside a Finder tell block the alias coercion is not needed

Hey

Thanks Stefan! I wouldn’t have figured that. I still learning all this stuff you know, and NOW I got a new one “set end of”. Thanks Again!

justin