Smart Rule to Assign Tags Based on Content

Hi All,

I’ve browsed the forum but I can’t seem to find exactly what I’m looking for, as such I’d be grateful for any help.

@BLUEFROG Kindly posted a near-possible solution here: Auto build smart rules - DEVONthink / Automation - DEVONtechnologies Community but I don’t think it is quite the solution for my requirements.

What I’m trying to achieve: I would like to use a smart rule with embedded script (that I can adapt per requirements) to search the contents of a particular database or group for a list of words (character names, locations, etc.) and assign a tag(s) based on this criteria.

For example, if I am breaking down a screenplay for further review and I have split each of the scenes into individual markdown tags (that do not contain any #hashtags in content), I want to be able to run the smart rule to search all the files contained within that project folder and extract the words I’ve assigned within the script to tags.

–> {“John”, “Route 66”, “Night”}

Appreciate the help in advance!

I‘m working on something similar but instead of defining which words should become tags inside the smart rule I create empty tags first. Still some experiments and testing needed but maybe I can share first results later

It’s unclear what you’re describing here.

You’re searching somewhere and I applying tags to something?

Screencaps may help.

I’ll try explain again, hopefully you can piece together an idea of what I’m trying to achieve by outlining my manual process :grinning:

  1. Search for a character name
  2. Tag the files that contain that name
  3. Search for a particular location
  4. Tag those files with that location
  5. Search for time of day (in screenwriting this is either DAY or NIGHT)
  6. Tag those files with the day/night

A time consuming process I’d love to try automate.

I start with a certain set of search criteria (a list of keywords I know I want to tag the files with). I know the project I want to search within. I just don’t know how to use Smart Rules to make my life a little easier so I can spend less time on meta maintenance and more time on the creative work.

One Smart Rule with a list of pre-defined search terms (words) that searches my database for those words. If the word is present, a tag is assigned. If the word is not present, no tag is assigned.

The best I can offer as an example of the workflow is this screenshot from a Hazel setup.

… but I think this might even be a bit simplistic…

I’d be grateful for the help! Thank you in advance.

Like so… ?

Note: I am not unifying the Tags for clarity of the Tags I premade.
PS: I nested the character tags just as an example. I am not advocating for or against this practice.

@BLUEFROG Thanks for the screenshot. That looks like what I’m trying to achieve, yes :+1:

I added the Tags to the tags group first then created a smart rule to process the files.

Note: I used two Content criterion just for your clarity. Also, you can use OR instead of the pipe (|) characters.

That worked a treat! Easy to adapt to other uses! Thank you for your help! :grinning: :+1:

Maybe I lost something in sintaxe. In my case I want to rename a compose name like “Rumo Certo” or “Old Way” (it is not just one word but 2 or 3). But no tags are ass. What I miss?

You’re welcome :slight_smile:

The Tags will only be assigned if they already exist in the database. Note what I said…

I added the Tags to the tags group first then created a smart rule to process the files.

The Add Tags From Document action might be more useful and doesn’t require this step. Just enter the desired tags and DEVONthink will add those which are found inside the document.

Indeed that’s another approach.

Sorry to open up an old thread… is it possible to run a Smart Rule using Add Tags from Document action for multiple tags, or do I have to create a Smart Rule for each individual tag I wish to apply this way?

For example, I have multiple student worksheets, some for elementary, pre-intermediate and intermediate, and I want to apply tags based on this criteria.

Grateful for the help in advance :slight_smile:

I put the logic into a script, building a string of tags
On completion, the tags are assigned from the string

Hey DT, would you mind sharing a screenshot of your smart rule please so I can see it visually :blush::pray:

I have multiple student worksheets, some for elementary, pre-intermediate and intermediate

Are these existing tags in the database?
If so, then Add Tags from Document should already work.

Thanks BlueFrog, I’m trying to bypass manually creating tags first and have the Smart Rule automate this process for me based on the content.

You’ve indicated the use of | before to separate the words in content to search for and then apply from a selection of tags in the smart rule, but I can’t remember how to do this using @cgrunenberg ‘s solution :melting_face:

I’m trying to bypass manually creating tags first


I’m lazy :joy: I don’t want to manually first create these tags… I want to tell the Smart Rule what tags I want based on content.