How do you remove a Tag from and existing set of tags within a note?


(Tom Diaz) #1

I am looking for the action code to remove an existing Tag, within $Tags, within a note that may have several preexisting Tags?

Use Case: I am trying to clean up some notes with old tags, many of these notes have more than 1 note. I am trying to run an agent to find notes that have a particular tag and trying to delete just this one tag. I want to be careful that I keep the other tags in place.

Thanks in advance.

BTW…I found this code for adding a tag to an existing set, but am lost how to remove a tag from an existing set. Action:$Tags=$Tags+“taxi;transportation”

Thanks in advance
Tom


(James Fallows) #2

I know (believe / suspect) that there is a way to do this.

I believe that @mwra or some other authoritative figure can tell you the exact way to do so.


Bonus I actually remember / have tested how to do this! Let’s say you want to remove the tag “taxi” from your list of entries, and let’s assume that $Tags is a Set-type attribute.

  1. Create an agent (or any other search vehicle, including an Attribute Browser) that has the query $Tags.contains(“taxi”)
  2. Create an action (or stamp, or whatever) that says $Tags=$Tags-“taxi”

In my test operation, this does the job. More here.


(Tom Diaz) #3

That worked! Useful for me to know. Many thanks.
Tom


(Paul Walters) #4

In addition to using a stamp, as suggested, an agent similar to the one described here works when you are sure you want the tag string in question removed everywhere.

Use the query suggested by @JFallows or use

$Tags.icontains("taxi")

since .icontains is case-insensitive

and use

$Tags=$Taxi.replace("Taxi","");

as the action for that agent. This sort of action is irreversible, so take care in its use. (The action can also be used in a stamp, if your removal action needs to be more granular as suggested above.


(Tom Diaz) #5

Excellent point especially since I like to monitor the lists of tags I use.

I learned years ago, the hard way, that tags can quickly become less useful if allowed to grow unmonitored and without structure for periods of time. This tip along with using the attribute browser to monitor and remove unwanted tags is very useful to me.

Thanks again to all on this forum.


(James Fallows) #6

I hadn’t actually applied the .replace operator and so am glad for this illustration of its use.

Also this coding illustration reminds me to clarify something from the example I offered above. Auto-correct in this browser turns “straight” quotes, like the ones you see in @PaulWalters’s original example, into curly quotes “like these” – and even like the ones that have been auto-subbed around “Taxi” into the quote above.

So if you copy-and-pasted the query and action in my post, they wouldn’t work because of the curly-quote issue. The proper form, with straight quotes, is:

$Tags.contains("taxi")     and      $Tags=$Tags-"taxi"

An outlier point, but if something weren’t working this could be a clue.
DAMHIK.


(Paul Walters) #7

Yes, it’s a good idea in Discourse to use one of the options for “preformatted text”. (Which is a silly term, since nothing is “pre-formatted”.)

Anyway:

  1. either press ⌘⇧C to create an indented block to enter text that will only have straight quotes; or,
  2. press the single tick symbol ` (on the same key as the tilde ~) and then type your text, ending with another tick; or,
  3. Type the text then select it and click the </> symbol in the Discourse editing box.

There are other methods. These are the more commonly used one.