Script: Assign selected tag to matching records based on content and name

sorry, i’m not sure i understand your question - my thought is, lets say a DB has 100 documents and 100 tags. I want to select 20 of those documents and have DT3 scan the text for anything matching those 100 tags. All the text, all the tags, only some of the documents. does that make sense?

Sure.

I think there’s a built in Smart Rule script for this, named “Tags - Assign”, I think.

Please create a Smart Rule with a “Execute script” action, then choose “External script” and try if that’s doing what you want. You can use the Smart Rule with selected records by using the contextual menu.

„text“ should have been „tags“.

@pete31 is correct about the Tags - Assign smart rule script.

However, you don’t have to use a smart rule. You could also use Tools > Batch Process: Execute Script and use the same external script, Tags - Assign.

@josieduffy does the Smart Rule script work for you?

it does! thank you so much! one more question, how does punctuation work when it comes to matching text to tags? for example - if my tag is “barbour county, alabama” and the text of a document says “barbour county alabama” will that be a match? what about the opposite scenario - no punctuation in the tag but punctuation in the text?

I guess both won’t match.

thanks pete! is there a way to ignore punctuation when matching? if not no worries, i just thought i’d check. Thanks!

No. But adding an alias without (or with) the punctuation should work.

but if i add an alias with a comma, won’t it recognize that as two separate tags instead of one whole one?

Ahh, yes, of course.

Mixed things up with this thread Tags with comma.

yes, i really wish there was a workaround for this! would be great if quotation marks worked, or a semi-colon separated tags instead of a colon.

i don’t know who to tag but it seems like it would be right to either be able to use punctuation in aliases or have the tag matching function ignore punctuation?

question about the original script in this thread, pete - does it only find the matching phrase, or will it match if both words are in the document regardless? so if i want it to find “red dog” will it only find “red dog” or will it tag red dog if it finds both red and dog? i’m hoping for the former but sometimes it seems to do the latter for some reason. could be my mistake though so wanted to check. thank you!

It only matches for red dog, not for red some other text dog. It’s the same behaviour as DEVONthink’s Smart Rule script “Assign tags”.

excellent

1 Like

@pete31 i want to thank you again for this script - it’s saved me HOURS of work. can’t tell you how grateful i am.

1 Like

Great to hear that :slight_smile:

@pete31 is there a way to do this exact same thing but find and tag all instances in all open databases?

If you remove in theSearchScope then all databases will be searched:

set theResults to search theQuery