# Document Renaming

**URL:** https://discourse.devontechnologies.com/t/document-renaming/67283
**Category:** Automation
**Tags:** automation
**Created:** [October 19, 2021, 2:32am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283 "2021-10-19T02:32:18Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 2:32am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/1 "2021-10-19T02:32:18Z")

</div>

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.

 ![Screen Shot 2021-10-18 at 19.30.56](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/c/7/c79dd76a82dde0a80ecb3d6cfa7e7d5a7f59d2a5.jpeg)

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.

---

<div class="post-metadata">

### Author: ![DTLow](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/dtlow/32/18161_2.png) [@DTLow](https://discourse.devontechnologies.com/u/DTLow)
#### Post date: [October 19, 2021, 2:38am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/2 "2021-10-19T02:38:57Z")

</div>

> [@kappabear](#):
>
> renaming the filename

My solution would be an Applescript

```auto
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

```

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 2:40am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/3 "2021-10-19T02:40:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![atdnorth](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@atdnorth](https://discourse.devontechnologies.com/u/atdnorth)
#### Post date: [October 19, 2021, 4:46am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/4 "2021-10-19T04:46:30Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 4:49am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/5 "2021-10-19T04:49:18Z")

</div>

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

Thanks!

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 4:51am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/6 "2021-10-19T04:51:03Z")

</div>

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 [developer.apple.com](http://developer.apple.com).)

---

<div class="post-metadata">

### Author: ![atdnorth](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@atdnorth](https://discourse.devontechnologies.com/u/atdnorth)
#### Post date: [October 19, 2021, 4:52am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/7 "2021-10-19T04:52:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DTLow](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/dtlow/32/18161_2.png) [@DTLow](https://discourse.devontechnologies.com/u/DTLow)
#### Post date: [October 19, 2021, 5:13am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/8 "2021-10-19T05:13:32Z")

</div>

> [@kappabear](#):
>
> AppleScript. Any suggestions on the best way to go about learning it?

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

---

<div class="post-metadata">

### Author: ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)
#### Post date: [October 19, 2021, 7:33am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/9 "2021-10-19T07:33:44Z")

</div>

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)](https://bru6.de/jxa) explains a bit about JavaScript for Automation.

---

<div class="post-metadata">

### Author: ![rmschne](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/8baadc/32.png) [@rmschne](https://discourse.devontechnologies.com/u/rmschne)
#### Post date: [October 19, 2021, 7:38am UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/10 "2021-10-19T07:38:51Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)
#### Post date: [October 19, 2021, 3:16pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/11 "2021-10-19T15:16:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 3:20pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/12 "2021-10-19T15:20:16Z")

</div>

Thanks Big Jim! 🙂

---

<div class="post-metadata">

### Author: ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)
#### Post date: [October 19, 2021, 3:22pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/13 "2021-10-19T15:22:55Z")

</div>

My pleasure.

Definitely check out **[https://macscripter.net](https://macscripter.net)**. It has long been _the place to be_ and all the heavy hitters have or are active there.

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 3:23pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/14 "2021-10-19T15:23:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 4:03pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/15 "2021-10-19T16:03:52Z")

</div>

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! 🙂

---

<div class="post-metadata">

### Author: ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)
#### Post date: [October 19, 2021, 4:13pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/16 "2021-10-19T16:13:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kappabear](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/41988e/32.png) [@kappabear](https://discourse.devontechnologies.com/u/kappabear)
#### Post date: [October 19, 2021, 4:27pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/17 "2021-10-19T16:27:01Z")

</div>

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! 😂 (Kidding!) Thanks for making it available, and I look forward to making my way through the contents.

---

<div class="post-metadata">

### Author: ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)
#### Post date: [October 19, 2021, 5:13pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/18 "2021-10-19T17:13:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dashard](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/dashard/32/4251_2.png) [@dashard](https://discourse.devontechnologies.com/u/dashard)
#### Post date: [October 23, 2021, 7:28pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/19 "2021-10-23T19:28:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Stephen\_C](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/stephen_c/32/8107_2.png) [@Stephen\_C](https://discourse.devontechnologies.com/u/Stephen_C)
#### Post date: [October 23, 2021, 8:09pm UTC](https://discourse.devontechnologies.com/t/document-renaming/67283/20 "2021-10-23T20:09:44Z")

</div>

\<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!).

Stephen

[Next page](https://discourse.devontechnologies.com/t/document-renaming/67283.md?page=2)
