Smart groups with placeholder in tags

I love Devonthink for its powerful features and I am trying to explore some automation lately.

I use DT to sort my taxdocuments into smart groups using tags. The tags are “tax 2019” or “school 2019” for example. No every year I have to manually set up smart groups and have to manually change the year.

Is there a way to use placeholders in tags? So I could set up smart groups for a tag like “tax [current year]” or “school [last year]”. That would help and I always would have sorted my documents for the last and the current year.

Or maybe there is a workaround to solve this problem. Thanks in advance.

If I’ve understood correctly I think you could use a smart rule along the following lines:

2020-05-17_09-46-39

Your rule might be simpler than that, of course, but the essence of it is that it files by year in the folder you specify.

Stephen

Not quite. The year is part of the tag name. The creation date of the file might be off by one year. Thanks anyway…

Perhaps this will work

Be sure in Preferences/Import you choose Convert hashtags to Tags:

image

Set up a Test Templates folder like this with an .rtf file called:

Template Tag Test %year%.rtf like this:

The contents of that new template should be like this:

image

Then go to Data/New from Template and choose your new template:

And now all of your current year tags have been created:

That’s possible since version 3.5:

The placeholders can be inserted via the contextual menu.

That is also cool and helpful, thanks. I can use that in my setup, but it doesn’t solve the problem I am working on. Let me publish a screenshot at the end of this thread to clarify the problem I am working on…

This should return all documents with the tag “tax 2019”. But it does not work. Is this possible somehow?

As there’s no placeholder for last year, an Execute Script action plus a custom script is probably the best option.

Ok, thanks for all the help. In that case, this might be an idea for a future update…

I always put a date string in the document (i.e. receipts or my own bills) like so
company yyyy-mm-dd more infomation
and set up a smart rule that collects all documents with (e.g.) 2019- in their name. That way, I can assemble most tax-related documents. Exceptions are receipts for donations, which usually arrive only at the beginning of the next year. But those are easily handled manually. As is the creation of the smartgroup once a year.

I created a small JavaScript example that shows how one can create a smart group programatically.
Notes:
It will create the group only once, i.e. you’ll not end up with several identical named versions of the smart group.
You have to adjust the values for dbName etc.
The thingy is wrapped inside an automatically executing function: You can run it from script editor or from DT3’s script menu but NOT as a script inside a smart rule. In order to do so, you’ll have to wrap it inside the appropriate construct.
The search string (searchPredicate) can of course be adjusted, so if you’d rather search for tags than for parts of the name…

(() => {
let app = Application("DEVONthink 3");

app.includeStandardAdditions = true;

let dbName = "ck Privat";
let baseName = "Tax";
let year = (new Date()).getFullYear();

let fullName = baseName + year; /* use (year-1) to collect records for last year */

/* Create Smart Group "TaxYYYY" */
let r = createRecordUnlessExists("ck Privat", "smart group", fullName);
r.searchGroup = getDBByName(dbName);
r.searchPredicates = "name:~" + year + "-";


function getDBByName(dbName) {
  return (app.databases.whose({name: dbName})[0]).root();
}

function createRecordUnlessExists(dbName, recType, recName) {
/* Creates record of type recType and name recName 
in database "dbName" or returns existing group */
let db = getDBByName(dbName);

var rec = app.search("name:" + recName + " kind:" + recType, {in: db})[0];
if (rec === undefined || rec === null) {
  rec = app.createRecordWith({type: recType, name: recName}, {in: db});
}
return rec;
}
})()

Thanks for the support. This is an excellent forum!