Need help with script to rename a record

I’m racking my brain trying to figure out a how to write a script in Applescript or Keyboard Maestro to rename a record by adding the file creation date at the beginning. I would like to add the date formatted as YYYY.MM.DD along with a hyphen before the original name. The final product should look like this: YYYY.MM.DD - Original Name.

Any assistance will be greatly appreciated…

Thank you for your assistance, Jim. I’ll follow-up with the file you referenced…

You’re welcome.

Thank you for posting the script @korm

I was just about to post an Applescript that does exactly what I need. It’s a modified version of the one @BLUEFROG posted a link to above.

I tried to paste the compiled Applescript into this post, but the formatting is lost. I’d appreciate the procedure for pasting and preserving the formatting…thanks.

tell application id “DNtp”
repeat with thisRecord in (selection as list)
set recordName to (name of thisRecord)
set creationDate to (creation date of thisRecord)
set thisMonth to texts -1 thru -2 of (“0” & (month of creationDate as number))
set thisDay to texts -1 thru -2 of (“0” & day of creationDate)
set thisYear to year of creationDate
set titleDateString to ("" & thisYear & “.” & thisMonth & “.” & thisDay & " - ")
set name of thisRecord to titleDateString & recordName
end repeat
end tell

Use three backticks.

```
script

```

Note: You have to paste it again as plain text as the previous version without backticks is messed up.

Use three backticks.

Thank you. That did it!!

	repeat with thisRecord in (selection as list)
		set recordName to (name of thisRecord)
		set creationDate to (creation date of thisRecord)
		set thisMonth to texts -1 thru -2 of ("0" & (month of creationDate as number))
		set thisDay to texts -1 thru -2 of ("0" & day of creationDate)
		set thisYear to year of creationDate
		set titleDateString to ("" & thisYear & "." & thisMonth & "." & thisDay & " - ")
		set name of thisRecord to titleDateString & recordName
	end repeat
end tell