Using the $Tags attribute to create a note containing a list of note names

I rely on a reference prototype that I created for a set of research notes and it uses the $Tag attribute. What I would like to do is create a note that generates a dynamic list of note names based on a specific value of $Tag. I realize that I can view this information in the Attribute Browser, but I want to be able to inspect, review, and reference this list within the context of a single note. This dynamic list of notes will run between 30 - 40 note names at any give point in time. I suspect there are several ways to do this. Any guidance on a preferred way to accomplish such a task is greatly appreciated.

To be clear, are you referring to the system attribute Tags (note spelling), or have you made a user attribute called Tag?

To make a note for every value of an attribute—system or user is very easy:

  1. Get all the discrete values as a list using values(). Note the syntax, in the linked article, using the name of the attribute without a $-prefix, thus values("Tags"). The operator needs the name of the attribute value, i.e. "Tags" vs "$Tags".

  2. Make a new note and pass that list (optionally sorted case-insensitively) to the note’s text, formatted so as to give a list item per line (i.e. each $Text paragraph is one source list item), like so (I’ll do it for the system ‘Tags’ attribute):

$Text = values("Tags").isort.format("\n");

values() gives us the list (i.e. "car;boat;train;bike;...etc.") of unique tags in use. The .isort sorts the list case-insensitively (i.e. AaBbCc…etc. and not A-Za-z) and the .format() replaces the list delimiters (semi-colons) with line breaks. The whole is passed to the note’s $Text, as a sorted text ‘list’ of unique Tags values:

bike
boat
car
train
  1. Explode the note’s $Text (see linked article for process details). Explode on paragraphs (as values may not be single word and might contain punctuation characters). This will make a new note per source $Text paragraph (text line) with the source value as the new note’s $name and $Text. If you don’t want the value in the new note’s $Text, ‘Omit text’ in the Explode set-up (qv).

  2. Finish up. You may want to move the new notes elsewhere and remove the source note. The Explode can also run action on the new notes or set prototypes, etc.

If that seems long it is only because I’ve described what’s going on. the process, once you know the action code for values() and the explode set-up will likely take you less than a minute. If you mess up the Explode part, simply delete the new child notes and do the process over again paying closer attention to the settings.

I meant the $Tags attribute.

My need is a bit more basic. What I am looking for is the creation of a single note that lists all note titles that have been assigned to a specific tag. I am not looking to do this for every tag, only a select few. I realize that I can see all notes assigned to a specific tag in the Attribute Browser, but if possible, I’d like to create a process that generates the listing of note names in a single note based on a single tag.

For example, I have a tag value called “luminosity.” I want all note names that have been tagged “luminosity” listed in a single note.

In retrospect, I think the title of this posting should be changed to “note names” listing. Thanks for helping me.

OK, create a note and give it this edict:

$Text = (collect(find($Tags.contains("luminosity")&$IsAlias==false),$Name)).isort.format("\n");

Which gives you the note you asked for. Using an Edict stops the query running all the time.

However, the above also hard-codes the search value. Whether you want to clone the note or run a different Edict within it, it makes more sense to parameterise the input. So, we add $Tags as a Displayed Attributes for the note and select only one value from the pop-up list of used $Tags values.

$Text = (collect(find($Tags.contains($Tags(that).at(0))&$Name!=$Name(that)&$IsAlias==false),$Name)).isort.format("\n");

Firstly, we change the "luminosity" search string for $Tags(that).at(0). This returns the value of the listing note’s $Tags, with the .at(0) as a safety measure in case you mistakenly set more than one value for $Tags in the listing note. The $Name!=$Name(that) argument ensure the listing note is not included in the list of matches. The $IsAlias==false argument avoids duplicates by ignoring any matches that are aliases, so only originals match the term.

In the latter seems complex. Don’t worry, just use the code and see what happens. Once you’ve seen it work it won’t seem so intimidating.

Just to say what might be obvious to you: the usual way to do this is to make an agent that lists the names of notes that match your criteria. If you just want it for a moment, that’s fine: no need to keep it after you’re done.

You can select all the agent’s children in an outline view, copy, and paste that into another note’s text to get the list.

But nothing wrong with this approach to a dynamic listing, either.

Thanks again for the help. The first edict worked great! Thanks!
I used the code in the parameterised example but could not get it to work.

Yes, using an agent was my first choice. However, curiosity got the better of me, so I decided to see if I could automate the entire process.

Here is a working example: Listing test.tbx (77.2 KB)

Thanks!