Create report with list of tags

Hello all,

Thank you for your consideration. I have the following question. In the same manner one can e.g. generate a TOC report. I wonder if a script exists that allows one to output a report that for a particular folder simply lists all tags that are associated with both the main folder and the files, grouptags and subfolders within that folder.

Apart from a little SQL my coding abilities are poor, but I might be able to amend an existing script that does something similar. Alternatively, perhaps someone is willing to help with or without payment.

Cheers

Welcome @Erika

So you just want a raw list of tags used in a particular location? For what purpose?
If you’re just interested in seeing the tags, have you looked at the Tools > Filter > Tags pane?

I would generate the report using Applescript
I actually generate ToC reports for my projects

Can you provide a sample of how you want to see the report

1 Like

The following JavaScript script creates a Markdown file containing the tags of the records in the currently open group as a list. The file is created in the group itself and called “Tags for group <groupname>”

(() => {
  const app = Application("DEVONthink 3")
  const currentGroup = app.currentGroup()
  const records = currentGroup.children();
  const tagsList = [];
  records.forEach(r => {
    tagsList.push(...r.tags());
  })
  const uniqueTags = new Set(tagsList);
  const text = Array.from(uniqueTags).sort().map(t =>  `- ${t}`).join("\n");
  const newRec = app.createRecordWith({name: `Tags for group ${currentGroup.name()}`,
     type: "markdown", "plain text": text},{ in: currentGroup});
 })()

The script makes use of JavaScript’s Set object to reduce all tags to only one occurrence (a set can contain each element only once, while an array can contain an arbitrary number of the same element). Therefore, it

  • first creates a Set from the tagsList build in the forEach loop
  • then it creates an Array from that Set with Array.from(…) which contains all tags only once,
  • sorts this Array with sort()
  • builds a new Array with map whose elements are built by prepending a "- " to the tag
  • and finally, joins all these - tag entries with newlines, effectively creating a Markdown list.
1 Like

Hello all, thank you for the welcome and responses

The output I require appears to be no different than the filter tag option with results displayed in list format. Unfortunately, it is not possible to manually copy its output into a text file. It would also become laborious since I have many folders for which at certain points in time I require updated information.

I organise my data in a particular manner and this data is subsequently accessed through various means. Hence a text file report is required. I have parent folders that serve as categories and I require an aggregated report view of all the tags used for and within that category.

I envisage a simple list of tag names ordered alphabetically without name duplication in plain or ‘hyperlink’ text format - and with or without the parent folder name at the top.

A more detailed version would list the tags in one column and then related files and folders in a second column. However, I do not require this in the immediate future.

Let me know your thoughts.Thanks.

Chrillek - You just wrote your message as I wrote and posted my mine. Thank you, let me read it now :slight_smile:

It would also become laborious since I have many folders for which at certain points in time I require updated information.

The Tags filter pane is the best option if you need to view updates as it happens on-the-fly. Updating a file isn’t done automatically. How often would you anticipate changes to the tags?

I organise my data in a particular manner and this data is subsequently accessed through various means. Hence a text file report is required.

More clarification on they why of this would be useful, e.g., what you’re actually using this for.