Change name from YYMMDD to YYYY-MM-DD

Hello everyone,

I am currently in the process of moving most my documents from my finder storage to DEVONthink to have everything in one place and use this opportunity to rename the files. Unfortunately I am having a hard time with batch renaming in DEVONhtink. I used to store dates in the format YYMMDD and would like to change these to YYYY-MM-DD but cannot figure out how to do this easily.

From this post (Smart Rule to delete first two Numbers of File names) I know you can use RegEx, but I have no idea on how to use them.

Could anyone please help me or does have a better idea? One other idea I had was to rename them with a renamer program prior to importing to DEVONthink but that changes the document date (last changed) which I need for categorizing.

And considering how mighty RegEx seem to be, does anyone have a good source for learning them (total beginner)? Thanks! :slight_smile:

Thank you very much!



The title of your post seems to indicate the exact opposite of what your text says Let’s stick with the text, then the search expression would be
(\d\d)(\d\d)(\d\d) (YYMMDD)
and the replace expression
20\1-\2-\3 (20YY-MM-DD)
if you’re using the rename with regular expression script in DT. And things get hairier if your years include the previous century…

There’s a batch rename option, too. But I’m not at my Mac now, so I can’t check that.

1 Like

Hello chrillek,

thanks. Yes, I mixed the tiles up. I am currently a bit under the weather. Sorry.

Thanks, I will try your script. I only need 20th century. :slight_smile:

I did look int the Apple Scrips options but couldn’t find anything that could help me.

All the best


I didn’t post one. Only the expressions to use with the script that comes with DT.

Ok, I tried it with a Smart Rule and the batch renaming and I successfuly changed the date format. Unfortunately I did also remove the rest of the file name. How do I tell DEVONthink to keep the rest of the name? Thanks!

My criteria:
scan name - regular expression - (\d\d)(\d\d)(\d\d)
change name in 20\1-\2-\3

1 Like

Please pardon the wrong wording. With script I was referring to your RegEx expression.

I seriously suggest reading and learning about regular expressions – otherwise you’ll be stuck in a “recipe” trap and get lost there when the cook is out.

Assuming your file names are somethingYYMMDDsomething else,
will match them, and
Will change only the YYMMDD part. Hopefully.


You’re a godsend! This worked like a charm! Thank you soooo much!

Yes, that much I figured when I found out about them. Do you have any good ideas where to start for a newbie?

Thorough but very good sites…

and a cool RegEx playground…

But be aware this is a rabbit hole with no discernable end.


Great! Thanks!!!

You’re welcome.

By the way, for mobile from the Script Debugger developer…

And while it’s not verified for macOS, it actually runs fine on a Mac in my testing :slight_smile:


Nice! I will keep that in mind when I start learning. :slight_smile:

By the way: In case your iPad or iPhone App is too small for macOS, this tool can change the text size of the apps. Haven’t tested it yet but heard a lot of good about it.


Applescript would have been my solution
Regex isn’t supported, but I find the coding clearer
Something like

tell application id "DNtp"
	set theSelection to get selection
	repeat with theNote in theSelection
		set theName to name of theNote
		set newName to "20" & texts 1 thru 2 of theName & "-" & texts 3 thru 4 of theName & "-" & texts 5 thru -1 of theName
		set name of theNote to newName
	end repeat
end tell

Cleaner? In the eye of the beholder, probably. But that solution suffers from the same problem as my first attempt. Worse: it works only with names beginning with YYMMDD. And it did not even check if that’s what the name begins with.
While a regular expression simply does nothing of it doesn’t match the given pattern. More robust.

Verification would be a useful addition
I think the applescript code would be
If length of theName is >= 6
If texts 1 thru 6 of theName is integer

(Not tested)

That does not compile on my machine. You want ‘text’ - singular.
It also is not safe:

text 1 thru 6 of "23051 " as integer --> no error; trailing space is ignored

You need to check that each & all of the 1st 6 characters are integers:

set t to "230513 should be a date"
set isDate to false -- safeguard against other errors

repeat with i from 1 to 6
		text i of t as integer
	on error
		set isDate to false
		exit repeat
	end try
	set isDate to true
end repeat

if isDate then
	-- rename this item
end if
1 Like

Now we’re getting there. A gazillion lines instead of a single RE :wink:

1 Like

If checking each digit, I’d go with
if text i of t is not in {“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”} then

1 Like

For what it’s worth: Tasks like writing that AppleScript are routinely solved by ChatGPT. I’ve not checked the following output, but after a couple of iterations it usually works pretty well. So no guarentees, just something to keep in mind.

Of course, you can also use chatGPT to help you with regular expressions:

Edit: After consideration, it might be a bad idea to rely on chatGPT for a more rare language like AppleScript. In my opinion, it can still give you ideas. Always check code that you copy from the Internet!! be it human or machine generated (and who knows which is which anyway).

And routinely, ChatGPT creates wrong code. Especially for AppleScript. We’ve been there. So, what is it worth?

Why are you posting possibly bad or wrong code? And what, frankly, is the point of posting worse code than has been posted before to solve the same problem (not only in this thread, but many times in this forum)? And why use a screenshot so that nobody can copy/paste the stuff, instead of actual code?

And you can, of course, use or other sources to learn something. Be it AppleScript or JavaScript or Regular Expressions. Instead of having a glorified ape demonstrate that it can do some kind of text analysis (Hello Eliza!) and throw back code at you (and all of us) that is neither new nor good nor robust.

And this thing is even just blabbing: “Adding” (rather “prepending”) the string “20” to another string is by no means a “logical operation” (as there are no logical operators involved), it is a simple string concatenation. Which, again, proves that it doesn’t know anything. It just does text processing.