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.
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!
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.
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!
scan name - regular expression - (\d\d)(\d\d)(\d\d)
change name in 20\1-\2-\3
Applescript would have been my solution
Regex isn’t supported, but I find the coding clearer
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
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.
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
set isDate to false
set isDate to true
if isDate then
-- rename this item
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.
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 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.