Change creation date based on file name

When I archive Drafts note over to DEVONthink, the creation date is set to the date when I did the archiving. However I would like to change the creation date to the original creation date of the Drafts note.

Currently, all my Drafts notes are titled like this “# Title - YYYY-MMDD-HHmmss”.

Does someone currently have a script that updates the creation date with the date in the filename?

Are referring to the Date Added or the Date Created?

Date Created

Assuming “MMDD” is a typo and you use “MM-DD” this script will do it. Otherwise you’ll have to adjust it.

-- Set creation date based on name "# Title - YYYY-MM-DD-HHmmss”

tell application id "DNtp"
	try
		set theRecords to selection of viewer window 1
		if theRecords = {} then error "Nothing selected."
		
		repeat with thisRecord in theRecords
			set theName to name of thisRecord
			set theFileName to filename of thisRecord
			
			if theName = theFileName then
				set revPath to reverse of characters in theFileName as string
				set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
				set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
			end if
			
			set theCreationDate to creation date of thisRecord
			
			try
				set seconds of theCreationDate to (characters -1 thru -2 in theName as string) as integer
				set minutes of theCreationDate to (characters -3 thru -4 in theName as string) as integer
				set hours of theCreationDate to (characters -5 thru -6 in theName as string) as integer
				set day of theCreationDate to (characters -8 thru -9 in theName as string) as integer
				set month of theCreationDate to (characters -11 thru -12 in theName as string) as integer
				set year of theCreationDate to (characters -14 thru -17 in theName as string) as integer
				
				set creation date of thisRecord to theCreationDate
			end try
		end repeat
		
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

It’s THE downside of Drafts that it keeps its notes locked in a database. Because of that the moment you move something out of it it actually creates a new file. And there goes the create date.

That’s the reason why I switched to 1Writer which is not by far as customizable as Drafts. But customizable it is and, like Drafts (on iPhonePadOS), allows to instantly write after launch. And it can be set to save the notes, for example, in an iCloud drive folder which DEVONthink indexes.

Speaking of customizable/programmable: Can’t Draft’s URL action that sends the note to DEVONthink set the create date directly so the detour over the file name and a Smart Rule would not be necessary?

It wasn’t a typo, I personally don’t split out the date and month.

I adjusted the script to work with the MMDD and it works perfectly now.

So thank you for the script, I totally didn’t think to just reverse the filename to get the timestamp. I thought I had to regex it out. You’ve saved me so much time!

1 Like

I hate how Drafts notes are locked in a database too, but I just love all their Actions and stuff, so I find it hard to move away from it.

I don’t mind keeping the creation date as part of note titles - sometime file creation dates are just unreliable because files can get moved around and creation dates changed (I mean, who knows if I move all my notes out of DEVONthink in the future and all my creation dates change again?)

Also, I use the creation dates in my titles as unique IDs in my semi-Zettelkasten system. Even note titles can change, but the unique ID never would. So (for now) this all works for me.

With regards to URL actions, DEVONthink doesn’t allow the change of creation notes via URL scheme. That would have been very handy too.