Copy Modification Date and Rename a group of files?

Is it possible via applescript or another method to have a file renamed with the CreationDate in the prefix?

I just downloaded about 120 emails into DevonThink Pro and would like to have the creation date in the file name for export. Ideally, I’d like to select them all and apply an applescript, rather than go one by one…

I saw both “Add Prefix” in the Rename submenu and “Copy Creation Date” so I figured you could “combine” the two… although I have NO knowledge of applescript and I’m sure its just not that easy…

Thanks in advance.

1 Like

Here you go. You didn’t specify how you want the date string to appear, so I guessed and gave you two options.

Set the variable shortDate to 1 to get: 4/27/11

Otherwise, set shortDate to something other than 1 to get: April 27, 2011

tell application id "com.devon-technologies.thinkpro2"
	set shortDate to 1
	
	set theDatabase to current database
	set theSelection to selection
	if theSelection is {} then error "Choose some records"
	
	repeat with thisItem in theSelection
		
		if shortDate is 1 then
			set myDateString to short date string of the creation date of thisItem
		else
			set myCreateDate to the creation date of thisItem
			set myDateString to ((month of myCreateDate) & " " & (day of myCreateDate) & ", " & (year of myCreateDate)) as string
		end if
		
		set myName to the name of thisItem
		set the name of thisItem to myDateString & " - " & myName
		
	end repeat
	
end tell
1 Like

Thanks for this Krom!

I set the short day to “l” and rearranged the dates to read y-m-d. Everything reads correctly, except the month. It’s writing out the month and not giving me the digits.

I’d like for my date format to read 2011-05-22 and as of now, it read 2011-May-22.

What will I need to do to correct this? Thanks again.

Thanks for this Krom!

I set the short day to “l” and rearranged the dates to read y-m-d. Everything reads correctly, except the month. It’s writing out the month and not giving me the digits.

I’d like for my date format to read 2011-05-22 and as of now, it read 2011-May-22.

What will I need to do to correct this? Thanks again.

A little help bump for my question in the post above? Any help is greatly appreciated :smiley:

This should work-note that there is no option for a long date as korm posted. Edit the script to add a space before and after the ‘-’ in the third line from the bottom of the code if you want that separation. A document created March 7, 2011 and named ‘My Document’ will be renamed to ‘2011-03-07-My Document’.

tell application id "com.devon-technologies.thinkpro2"
	set theDatabase to current database
	set theSelection to selection
	if theSelection is {} then error "Choose some records"
	
	repeat with thisItem in theSelection
		set myCreateDate to the creation date of thisItem
		
		tell myCreateDate
			set theShortDate to year & "-" & (characters -2 through -1 of ("0" & (month of myCreateDate as number))) & "-" & (characters -2 through -1 of ("0" & day)) as text
		end tell
		
		set myName to the name of thisItem
		set the name of thisItem to theShortDate & "-" & myName	
	end repeat
end tell

Thanks. This worked like a champ!