Search for a TAG starting with

I’m looking for a capability to extract a specific TAG name. When I want to discuss something with somebody I jot down a note for it. That note I tag with “WithNAME”. Is there a mechanism to find that specifi tag within all the tags (if there are more) and use it in another action step?

Using a script action step, you can loop through all the tags you have, look for the substring for the name and when you find a match, keep a note of it, then do a search for any draft containing any of those tags.

Now that isn’t necessarily one tag, so you can’t necessarily “just use it” in another step. You can use it in subsequent steps - directly via a script step or indirectly if you set a template tag, but unless you have only one matching tag, chances are other steps might not cope so well if they are expecting a single tag.

Does that help?

I can imagine to use a script. But what script can I use to perform that particular action? I have no clue about writing code

In that case can you describe end-to-end exactly what you would like to do? There’s only a partial description above, and a variety of ways you might be wanting to practically apply it.

The tag filter view has a search field. If you start typing it will filter the list of available tags to just those starting with what you have typed.

You can then select and add those tags to the filter to display only drafts with those tags assigned in the draft list. Make sure the filter is set to display “Any” of the selected tags, not “All”.

I want to post a note from DRAFS to a journal note in BEAR. That journal note is related to - in this case - a BILA which I have with different persons.
So, I already have a script which can add a draf note to a BEAR note. But to select the correct BEAR note I need to know for which person it is. Therefore I tag the note with the intended person. So the tag is something like “WithSander”. In this case the particle note should be added to the journal created for Sander. Everything is already in-place to proces. I only need to extract the TAG WithSander (so I know the person) AND ideally remove the prefix With. If I can have that name to a variable, I can use it in a next step action

Let me see if I have this correct. You want to enter a person’s surname. This is to be matched to a Drafts tag, and always have a prefix of “With” on the person’s name for the Drafts tag. From the resulting list of Drafts you want to pick one, and only one, and send it to Bear tagged with the Person’s name and any other tags the draft has, other than the “With{Surname}” tag.

Is that accurate?

the mechanism of tagging is not the issue, this manually done when working on a note. The script looking for is to read the assigned TAGS and extract the TAG starting with WITH. Then that particular tag need to be added to a variable and preferable the prefix WITH needs to be removed. The I can use the variable to process in other actions

While what you are describing is possible, might I suggest a slight alteration to your workflow? It would be a lot more efficient to use more than one tag. Use the name as a separate tag, and have a tag indicating the draft is yet to be processed, so the logic would be something like:

  • tag draft with two tags, “with” and “sander” (or “with” and “other-name”, etc.)
  • have a workspace that looked for all drafts tagged “with”
  • use action to loop over drafts in “with” workspace inbox, using the other tag to determine the name - have the action post the note to bear, remove the “with” tag, and archive each draft.

That allows you to easily filter all your unprocessed notes using the “with” tag workspace.

that is even no problem, however, how should the LOOP looks like. This should be a sort of while function, but I do not know how to code this in drafts

Something along the lines of the below. See reference for more methods available:

// query a list of drafts in the inbox with the tag "with"
let drafts = Draft.query("", "inbox", ["with"]);
// loop over the array of drafts
for (let d of drafts) {
   // `d` is a variable representing the draft

Is there also a method to loop the tavs of the current note instead of filtering notes in (in this case) the inbox?

I have found below script, which create a string of tags to be used with BEAR and assign it to a variable hashtag. If I could add a query to this string to find the “with”-tag I fine

// make template tag
// with draft tags as #hashtags for Bear
let hashTags = => #${t}).join(", ")
draft.setTemplateTag(“hashtags”, hashTags);

Each draft has a tags property which is an array. You use a standard JavaScript array iteration for that.

But you seem to be switching your descriptions throughout. Are you processing a single note you have already selected and literally just want to use your as yet undisclosed action to remove text from a tag?

Again this comes back to needing you to describe precisely what you are doing. Step-by-step.

I’m thinking small tweak to your existing Bear action might be all that is required. To remove the word “with” from any tag passed to Bear.

Can you please take another try at providing details of what exactly you are doing? Example draft data, link to existing action, the steps you want to do manually/automated, and the ultimate result would allow us to give you what you want. Any gaps and we’re just running around in circles guessing to fill them :man_shrugging:t2:

Sorry “sylumer” as far I read it is already explained, but will do another try.

I make a draft - which I name a note.
In this note I jot down things I have to discuss with somebody the next time I see that person
The reason I write them down is to. Ot forget them
To have everything together I want to combine all these notes into one BEAR note
This happen throughout a day or even days or weeks, depends on when I speak to that person
I do not want to have all this information stored in drafts, so I want to process the note as soon as I finish what I had to write down
When I write down something I tag that note, one of the tags is the person where I have to discuss it with. To know understand that particular tag from other tags I start these tag with “with” for me to understand the person I want to discuss the topics with
When finished, I press the action button to process the note
The action should be find the correct person tag, so I know in further steps to which BEAR note I have to append the just jotted down one.
Therefore I’m looking for a “script” which will start with “with”. I can use the prefix as well, however prefer to have it removed to have the name only.
The I want to have that name assigned tona template tag for further processing

Do you under what I want?

Not fully, no. I still see gaps and other issues around what you have described. However, I have had a go at putting together something that I think does the sort of thing I think you might want and I have guessed at what I think could be logical steps you might want to happen around the various gaps.

Here is the action I have created for you:

With any luck, this will do something similar to what you are thinking of, but otherwise, it will hopefully give you some code you can utilise in building what you want.

Important Notes on the Action

  1. The action includes script that is heavily documented to help you understand what is going on.
  2. The action will process not just the current draft, but will process all available drafts in the inbox.
  3. The first action step calls another action. This action is part of my ThoughtAsylum action group. Utilising this action group meant I could use a prebuilt function to get all tags, and make full use of the class for working with the Bear app.
    • You must download and install the action group for this action to work.
    • It will download the TADpoLe code library, which this action makes use of, but do post any error messages should you get any.
  4. The second action step contains three settings you can specify. The prefix for the tags you are actively processing (I have defaulted this to “with” based on your example), the desired prefix of the title of the Bear note to work with (the full title consists of the actively processed tag without the “with”, prepended with this prefix), and a Boolean to allow you to set drafts that have been processed to be moved to archive.
  5. Drafts with two “with” tags would only be processed once if drafts are set to be archived.
    • This could be worked around this with a double pass, but as one of the gaps, I’ve left this one as a simple, single pass, and you can take this further yourself if you wish.
  6. The third action step contains a function that I make use of in the action.
  7. The fourth action step contains the core code that identified and processes the drafts.
  8. If there is a matching Bear note, it will update the first matched note, otherwise, a new note will be created.
  9. Bear notes are created/updated with all tags from the Drafts note being processed, but with the matched prefix removed on the active processing tag.

thanks, I will going through. However, there was no request about creating notes or append notes to BEAR. That part is working already. There is only a need to get the “with”-tag out of a DRAFT note

I really do not undrstabnd why everyboyd is creating scripts to read drafts. I need to read TAGs of the CURRENT draft. Or is that impossible?

As named before; I jot down something and process it immediately, I do not store notes in draft. Draft is - for me - an single entry point. So, I jot down something, and select an action what to do, this can be sending it to TODOIST, or in this case proces it for a dedicated NOTE in BEAR. Again, no need to provide information regards how to sent to BEAR or find the correct note in BEAR. That part is working already. I only want to get the TAGGING system, of DRAFT under control, where I want to read the just assigned tagging of the CURRENT DRAFT

That is not at all what I got from your earlier posts, sorry for the confusion.

I’m still a little unclear, however. If you are just sending to Bear, and Bear uses hashtags in the text, why are you using Drafts tags at all? Just type #sander in the text, that that will end up being a tag in Bear when you send the text over there.

If you want to assign tags in drafts, then the script snippet you posted above will convert tags assigned in Drafts to #hashtags and create a template tag [[hashTags]] which can be used in your URL action to send to Bear.

Yes, but to understand how to feed into that we need to know how you are accepting that. I asked you to post a link to the action you were using, but you didn’t, so I had to put together a way of doing it.

Not at all impossible, but the way to do it is to use a script, which is why we keep talking about and giving you scripts to do what you are asking.

There is a [[tags]] template tag to give you a CSV list of tags for the current draft, but you need to pick one tag and process that tag. Even if you had just one tag, you still need to process the tag to see if it starts with “with” in upper/lower/mixed case.

Scripting is how you do granular processing.

I read the following as you “want” to process immediately, but this can occur over weeks, and so you might process them after weeks.

Not true. There are several ways in which that action could work. Getting the tag into the appropriate format so you can use it is a key part of what you are trying to do. Again, this was why I had asked about it previously and noted its importance in how we answer your question, and why I ended up posting a potential solution that was independent of whatever the approach is that you are using at the moment.

Maybe you want something like this?