Tags to Wiki-Style Cross-Links

Tags to Wiki-Style Cross-Links - can this be done?

Objective: Run an action that will, based on selected “tag” - gather all Drafts titles in “Wiki-Style Cross-Linking” format and add these wikilink titles to the clipboard.

Looks like this:

  1. Invoke action (Let’s call it Tags to Wikilinks)
  2. Pop up calls for tag
  3. Enter desired tag
  4. Action collects all Drafts assigned to desired tag
  5. Converts said tagged Drafts titles to Wikilink format
  6. Places wikilinks in clipboard, 1 per line

Example:
3 Drafts with the tag: “coffee”

Drafts with tag “coffee” are:
Starbucks cafe latte
Nespresso espresso
Learn to make a longo

Tag “coffee” is entered at the start of the action.

Output is:
[[Starbucks cafe latte]]
[[Nespresso espresso]]
[[Learn to make a longo]]

Not bad to do. Below example shows the query and construction of the result. It has a hard coded tag name, but could be extended to get that tag value from a prompt:

// tag to lookup. could be gathered from prompt...
let tag = "my-tag";
// query for drafts with that tag...
let taggedDrafts = Draft.query("", "all", [tag]);
// setup var to store titles
let titles = [];

// loop over drafts, adding each title to results
for (let d of taggedDrafts) {
	titles.push(d.processTemplate("[[display_title]]"));
}

// turn titles into wiki-linked titles
titles = titles.map(t => `[[${t}]]`);

// create result string and put it in clipboard
let results = titles.join("\n");
app.setClipboard(results);
2 Likes

I wrote this months ago - can’t believe it did not post. My apologies for the delayed thank you.

Thanks so much for this @agiletortoise

I successfully worked prompts into a prior action - should be able to run it up from here.

1 Like

Seems after much research and attempts I’ve not been able to dynamically assign the tag via prompt as directed:

get that tag value from a prompt:

Wondering how I capture the tag value and pass it into the rest of the script?

Here’s how far I got:


// tag to lookup. could be gathered from prompt...
let tag = draft.getTemplateTag('[[prompt_text]]');

// query for drafts with that tag...
let taggedDrafts = Draft.query("", "all", [tag]);
// setup var to store titles
let titles = [];

// loop over drafts, adding each title to results
for (let d of taggedDrafts) {
	titles.push(d.processTemplate("[[display_title]]"));
}

// turn titles into wiki-linked titles
titles = titles.map(t => `[[${t}]]`);

// create result string and put it in clipboard
let results = titles.join("\n");
app.setClipboard(results);

That should just be…

let tag = draft.getTemplateTag('prompt_text');

Note, no brackets in the tag name. Alternately, you can actually just evaluate the tag with the template processor, in which case you would want the tag delimiters, like:

let tag = draft.processTemplate("[[prompt_text]]")
1 Like

Brilliant!!

I was close - actually feel good about that…

Thank you so much, @agiletortoise!

1 Like