copy modification date to creation date

I’d like to make a script that will take all selected files in the Finder and make the creation date the same as the existing modification date.

Specifically, I have files transferred from a PC disk (camera card), which typically don’t show a creation date (Get Info says " – ") but which contain a modified date, and I’d like to make the creation date the same.

I know this is probably rather simple but I’m not that well versed on scripting so I’m running into trouble.

I’m getting all kinds of errors, but right now I’m getting a “can’t get modification date” error.

Any help is appreciated! I’ve searched for a couple days to see if this question has been asked here but haven’t come up with what I’m looking for.

Also, eventually I’d like to have the script look for only .mpg files so I can use it in a folder action.

OK, Here’s what I’ve got so far…

   tell application "Finder"
	
	set sel to (get selection)
	
	set modDate to modification date of sel
end tell
tell application "Finder"
	
	set creation date to modDate
end tell


I would most likely look onto the shell “touch” to do this here are a few bits that should get you started. I don’t know if it would be better to pull the date through shell in a similar way. Im sure there are plenty of others here who can help you with that.

set theFile to choose file with prompt "Which file do you want to change?"
-- touch-change file access and modification times 
-- touch[-acfhm][-r file][-t [[CC]YY]MMDDhhmm[.SS]]file ...

-- touch -t Change the access and modification times to the specified time.
do shell script "touch -t 200603141647.36 " & quoted form of POSIX path of theFile
-- return (info for theFile)

Hi grouchguy,

neither the Finder nor the standard UNIX are able to change the creation date of a file.
The only way is the command line SetFile, which is part of the Developer Tools.
With Developer Tools installed (in the root directory of your start volume) you can use this (droplet):

on run
	set these_items to choose file with multiple selections allowed without invisibles
	change_creation_date(these_items)
end run

on open these_items
	change_creation_date(these_items)
end open

on change_creation_date(these_items)
	repeat with this_item in these_items
		set modDate to modification date of (info for this_item)
		tell modDate to set creationDateString to my lead_zero(its month as integer) & "/" & my lead_zero(its day) & "/" & year & "\\ " & my lead_zero(its hours) & ":" & my lead_zero(its minutes)
		do shell script "/Developer/Tools/SetFile -d " & creationDateString & space & quoted form of POSIX path of this_item
	end repeat
end change_creation_date

on lead_zero(value)
	return (text -2 thru -1 of ("0" & value))
end lead_zero

PS: on my machine there is a time difference of one hour between the created date string
and the real changed date.

Thank you so much, Stefan…I finally got around to installing the developer tools and indeed this does work as a droplet. Thank you!

However, I’m trying to alter the script so I can also run it from the script menu when targeted files are selected in the Finder, and I’m not having any success. Here’s what I’ve got so far:

tell application "Finder"
	copy the selection to these_items
	change_creation_date(these_items)
end tell

on change_creation_date(these_items)
	repeat with this_item in these_items
		set modDate to modification date of (info for this_item)
		tell modDate to set creationDateString to my lead_zero(its month as integer) & "/" & my lead_zero(its day) & "/" & year & "\\ " & my lead_zero(its hours) & ":" & my lead_zero(its minutes)
		do shell script "/Developer/Tools/SetFile -d " & creationDateString & space & quoted form of POSIX path of this_item
	end repeat
end change_creation_date

on lead_zero(value)
	return (text -2 thru -1 of ("0" & value))
end lead_zero

Any suggestions?
Thanks!

Hi,

the open handler creates a list of aliases, and the Finder selection is a list of file specifiers, which has different behavior.
This should work

tell application "Finder"
	copy the selection to these_items
	change_creation_date(these_items)
end tell

on change_creation_date(these_items)
	repeat with this_item in these_items
		set modDate to modification date of (info for (this_item as alias))
		tell modDate to set creationDateString to my lead_zero(its month as integer) & "/" & my lead_zero(its day) & "/" & year & "\\ " & my lead_zero(its hours) & ":" & my lead_zero(its minutes)
		do shell script "/Developer/Tools/SetFile -d " & creationDateString & space & quoted form of POSIX path of (this_item as alias)
	end repeat
end change_creation_date

on lead_zero(value)
	return (text -2 thru -1 of ("0" & value))
end lead_zero