Document Renaming

I receive a monthly PDF magazine that contains the date in the title in the form of “year-month” (2021-10). The contents of the magazine also contains the date but it’s in the form of “issue number / Month Name Year” (67 / October 2021). For years I’ve been manually renaming the filename to “Magazine Name - (2021-10) October 2021”, but I’d love to automate this process, but I can’t figure out how to do so.

The Document Date scan does not detect any of the dates in the document. Scan Name finds “2021-10” in the filename, but only as a string and not as a date, which means that I can partial rename the magazine to my preference, but not completely. I can rename it from “Magazine-Name-2021-10” to “Magazine Name - (2021-10)” but not add the “October 2021”, unless there’s something that I’m overlooking.

My solution would be an Applescript

tell application id "DNtp"
	set theRecord to content record
	set theName to name of theRecord
	set yyyy to texts 1 thru 4 of theName
	set mm to texts 6 thru 7 of theName
	set theDate to current date
	tell theDate to set {its day, its month, its year} to {"1", mm, yyyy}
	set theMonth to month of theDate
	set name of theRecord to "Magazine Name - (" & theName & ") " & theMonth & " " & yyyy
end tell

Yeah that makes 100% sense, but that would require me learning it. :slight_smile:

Simplest approach, as other posts on the forum discuss (and from personal experience), is to use the tool Hazel. It’s very simple to use.

(Note: it works prior to importing into DT; I use Hazel to rename the file into a set format and move the file into the Inbox; in DT, I have a Smart Rule to match the file name and move it to the final destination)


Hazel has the ability to Rename files to this extent!? I had no idea! I’ll download a trial!


You’ve piqued my curiosity, and now I think I’ll try to pick up AppleScript. Any suggestions on the best way to go about learning it? (I’ve looked at a few different websites, including

1 Like

Set up a watch folder (generally Downloads) for Hazel. It’s incredibly powerful and I use it for many of the repetitive things I download that must be filed. Most times I match on some unique text string or combination of strings that exists in the downloaded file.


I learn from looking at scripts posted in this forum,
delivered by Devonthink, and posted on the web

I’d actually suggest to learn JavaScript instead. It can do everything AppleScript can and a lot of things are simpler than in AS.
Also, AppleScript is limited to macOS, while JavaScript is available on most any platform and in every browser.
Blatant publicity stunt: Introduction to JXA | JavaScript for Automation (JXA) explains a bit about JavaScript for Automation.

1 Like

I do all this kind of stuff in Hazel, preprocessing a bunch of stuff, including renaming, before automatically entering into DEVONthink… Simple and relatively easy to duplicate for documents with different formats to mess with. Doesn’t rely on a programming language–I have too many of those in my backpocket already).

See the Help > Documentation > Automation chapter for the various options available, including links to some useful AppleScript sites.


Thanks Big Jim! :slight_smile:

1 Like

My pleasure.

Definitely check out It has long been the place to be and all the heavy hitters have or are active there.


Funny that you mentioned JavaScript as I’d been contemplating that for a while, as it will allow me to do a lot more across the entirety of my Mac. (I think the last languages that I learned (and promptly forgot) was Python or Ruby, and rarely used them.

Funny that you shared that particular URL, as I’ve had it open in my browser for 3 days, because I wanted to read it, but just hadn’t gotten to it yet! Thanks! :slight_smile:

Well, having written that stuff it kind of came naturally to me to mention ist :wink:

1 Like

Oh man, you shouldn’t have told me that you wrote the contents for the site! Just wait until I’m confused and have questions, as now I know exactly where to go for support! You’re in trouble now! :joy: (Kidding!) Thanks for making it available, and I look forward to making my way through the contents.

1 Like

You’ll find my e-mail address in the about section. Just drop me a line if need be.


While a fair argument could be made for learning JavaScript ahead/instead of Applescript, it’s simply not true to suggest that one can accomplish in JavaScript everything that one can with Applescript.

Learning Applescript is about the best gift a Mac user with a Mac-centric workflow can give themselves. Unix is next, then followed perhaps by JavaScript. If you’re a KM jockey then I’m safe to assume the Mac user part. If your workflows are also all Mac-centric, then I would recommend learning Applescript unreservedly. JS simply cannot do all that AS can. And AS + Unix is potently powerful.

1 Like

<Stands well back and waits>. Now this is going to be interesting (by no means seeking to counter the previous poster but…well, let’s see what happens!).