Smart Rule to Rename Based on Contents

I want to set up a smart rule that will rename a pdf from “untitled” based on contents from within. I see there is an option to use a text string, but I am not sure the syntax of telling DEvonthink exactly what look for. For example, how do I tell it to look for the word “subject” and use whichever words comes after it to rename?

Welcome @sweeneyj

You can use a Scan Text action and define the string as Subject *
Then use the Change Name action with the Document String placeholder found in the contextual menu of the text field for the action.

However, unless you’re dealing with very conforming documents, this may yield unexpected results, e.g., too much text.

Here’s an example…

Notice how it picked up the second sentence.

I would suggest the subject would be a single sentence not ending with a period, but if that wasn’t the case, you could ignore everything after the period with this smart rule…

1 Like

Thank you, this was very helpful. However, it is picking up all of the remaining text in the document and using that in the naming process. Is there a way to use something other than a period to limit how much texts returned?

You’re welcome!

  • Do you have example text to share?
  • And again, how conforming are your documents?

The documents are fairly confirming. The subject is always followed by another line that says Date. Here is an example:

Subject: Student: Student Information

Date:Thursday, September 15, 2022 at 10:49:23 AM Eastern Daylight Time

How can I get it to stop after “Student Information?” Or, maybe a better question to ask is how can I get it to stop once it encounters “Date.”

Is that supposed to read Subject: Student:, both with colons?


And for even more fun - the name is entirely generated from the header text!

:stuck_out_tongue: :wink:

What does the smart rule look like to return all of that info? This is what all of my documents look like, they are emails that have been converted to pdf files. I would love to have a smart rule that would rename the document by combining the subject and sender into the name.


While there is another approach with regular expressions, that is not a solution for everyone. In this case I used the Scan Text and Change Name functions, chained together to progressively build the name. And the other trick is the text field supports multiple lines. This means you cna use Option-Return at the end of the string to force only capturing from one line.

Here I just right arrow at the end of the line to show there’s a Return there.

And here is the smart rule for you to mess about with and learn from…
Rename from (904 Bytes)

I cannot thank you enough as this is exactly what I needed. I really appreciate it.

You’re very welcome!
I hope it encourages you that you don’t necessarily have to know scripting to do some thing in smart rules. :relaxed:

Any idea how to use this with information in the header of a markdown document?

Author: Thomas Krampe
Title: Example Document
Copyright: 2022 by Thomas Krampe

# Example Document
Here comes a lot of text...

It works if I have the information below the first headline, but not if it’s above. The following example works with “Date: *” as the scan string.

Author: Thomas Krampe
Title: Example Document
Copyright: 2022 by Thomas Krampe

# Example Document
Here comes a lot of text...
Date: 2022-09-26

If I change the string to “Title: *” it doesn’t.

Use it in what way?

I create md files from a template and all the names are and than I write my text and fill the values in the header like Title, Copyright and so on. I read this and my first thought was, cool I can automatically rename the file based on the title in the header.

Any idea why it works with text after the first header but not if it’s before?

Because metadata are by default not considered content. You can search the forum for threads on that, and there’s a hidden preference to change the behavior (see the manual for that). But I don’t know if seeing that preference solves your problem.

If not, you can always resort too scripting.

Various metadata fields like title, author or description are indexed and mapped to the document properties (see inspector), therefore the placeholders for document properties should work and a simple Change Name action be sufficient.

If IndexRawMarkdownSource is enabled and the database rebuilt, shouldn’t the Scan Text action find MultiMarkdown metadata headers?

It should. But it’s not necessary to get the title.

If it’s not necessary, how can we get this string with the Scan text action? On the other hand, is enabling IndexRawMarkdownSource a recommendation or are there other problems with this setting?

If i understand @cgrunenberg correctly, the title is stored in the corresponding metafata field. So you should be able too access this instead of using scan text.