Agent to Display Random Note

Hello, I’m new to Tinderbox and fascinated by its potential. But I am aware I am at the beginning of the journey… Please, be patient with me… :slight_smile:

What I would like to do is to create an agent or other automation that when triggered it displays a random note that:

Scenario A

  • note is from a specific prototype

Scenario B

  • note is from the root (any note, no matter its type)

The idea is to be able to “review” random notes.

Can anyone help me out with this?

Regards,

Santi

There are lots of ways to do this! Let’s look at one for scenario A.

  1. Make an agent that gathers all notes using the prototype Dinosaur
Name: Dinosaur Collection
Query: $Prototype=="Dinosaur"
  1. Make another note that will display the title of a randomly-chosen dinosaur
Edict: $Name=$Name(randomChild(Dinosaur Collection))

Why an edict? We could use a Rule, but then the chosen dinosaur would change every few seconds! An edict changes every hour or so, and also when we select the note; that’s closer to what we want.

Dinosaurs.tbx (214.2 KB)

The query finds all notes using the prototype ‘Event’:

$Prototype=="Event"

and

This query finds all notes from the root of the outline:

$Container(original)=="/"

But neither does exactly what you want. An agent has no discrete operator to limit the matched items to an arbitrary number of matches. Plus every time the agent refreshes (very quickly, in a small document), the selection might change and that is likely not what you want.

Not stated but implicit is you expect an agent to show only one note and then only until you’re done with it. So this begs some questions:

  • Of all the matching notes of the query (such as examples above), do you want the first—if so first by what order—or a random choice?
  • How you propose to indicate to the app you’re done reviewing and to show a different note at next update?
  • How do you propose to indicate to the app which notes are reviewed and not to be picked again? Or, how do you intuit the app would know this?

These clarifications don’t imply your question is wrong or bad, but simply unpack the choices you—the user—need to consider so you give the app sufficient info to show you the correct data in the correct context.

Don’t worry if you don’t know the answers to the above. Just say what you assume will happen, and why. We can then help with a solution that takes that into account.

But a second agent can do exactly that:

Query: first(/Dinosaur Collection 10)

Gets the first ten items in the dinosaur collection.

Indeed, but this requires a second agent which is a different point to the one I was making. No conflict there. :slight_smile:

Thank you!

Tinkering with this solution I was able to create an agent for each of the scenarios.

For the Scenario B I used ($Name) as query

1 Like

My challenge now is how to make this generated note have a link to the actual original note.

I tried this edict:
$Name=$Name(randomChild(Dinosaur Collection)); $Text="[["+$Name+"]]"

but unfortunately it does not create any link, just writes the note name between brackets. How could I do it so it would render as a ziplink?

Put plainly, there is no such thing as a ‘ziplink’. Tinderbox’s ‘zip’ method of link creation is a manual text input method for creating Tinderbox text links. Indeed, I don’t recall there being any action code method to generate text links—as opposed to note-to-note basic links. The ‘zip’ link creation method was added so those who only know how to use Markdown or wikis could easily make a text link in Tinderbox. An added benefit was for keyboard-only users who cold make a link without using the trackpad/mouse. A misconception—especially for those who have only ever make hyperlinks via HTML or Markdown—is that there is no requirement in hypertext terms to use anchor text. The latter is a limitation imposed by the design of HTML.

The question then remains are you adding a text link because you need one or because you assume that is the only way to link. If the latter, be aware Tinderbox is a hypertext tool; the Web is a partial implementation of hypertext. For note-to-note links (i.e. not links sourced within $Text), Tinderbox action code has a host of link-based operators: see here.

But making a basic link to the review note seems pointless as the agent already makes a (child) alias of the matched not. Select the alias to see the note—if you’re only using map view at present, try viewing the agent in outline view and things might be clearer. Select the alias found by the note and you are looking at that note, via the alias. In other words you likely don’t even need the agent to link to the review item. After all, once you’ve reviewed the note, why does the alias need to link to it.

I sense that, understandably, you are trying to make Tinderbox behave in the fashion of some other application/process with which you are more familiar. Of so, it might be useful to know what it is so we can figure out any false assumptions such experience is creating as to how Tinderbox works. :slight_smile:

Hello Mark, thank you for your response.

The issue here is that the Edict

does not seem to create an alias, it just seems to create a standalone temporary note with the name of randomly-picked note and empty text. Selecting the generated note opens a plain blank note. But not an alias of the real note.

Therefore the workaround I think of is to automatically insert a note-to-note link within $Text so I can jump to the actual note.

FWIW< I tried your method, and even adding an eval, I get the raw string. this shows, action code does not allow generation of new $Text that includes text links. I note that if for no other reason that someone can point out I am wrong! Here is the edict:

$MyString=$Name(randomChild(/Dinosaur Collection));
var:string vString = "[["+$MyString+"]]";
$Text=eval(vString);

The extra step with the variable was in case pre-making the bracket-enclosed string would help It doesn’t. Action code does not (at least, as at v9.7.3) support making text links from string data.

Here is the test file, $Text of “Test” is set by its edict: text-link-test1.tbx (131.1 KB)

BUT… note the above file’s agent “Random note agent”. Using the query:

$Name==$MyString(agent)

and agent Edict:

$MyString = $Name(randomChild("Dinosaur Collection"));

Note: trying to use query $Name==$Name(randomChild("Dinosaur Collection")) did not always result in a consistent result of a single match.

The agent’s edict finds a random item inside the target container and stores it in the agent’s $MyString. The query then looks for the note with that name and , if finding a match creates an alias. Select the alias and you are looking at the note. If you need to truly select the original, use menu EditShow Original (or +R).

No link needed! So, what am I missing (given that action code can’t simulate a zip-method link creation)?

Sorry, hit Reply by mistake, above post now fixed and link to TBX added.

This fails, as with $Name. Same problem. I’d wager the issue isn’t $Path vs. $Name data (or $ID, etc.) but that action code simply has no notion of the zip link-making method. Indeed, as a reason the method was added to the app was to aid creation of links via the user’s typing into $Text, why would it?

I can see a point in allowing the user to add $Text containing (constructed) text links, but I think that would be a feature request for someone to make. Iff taken up as an action code operator then the faux-Markdown code isn’t needed as we’d simply pass the relevant arguments to the operator.

Actions cannot make text links, and the ziplink approach above, while very clever, will not work.

You could make a basic link with linkTo. The Links pane shows links, so it’s almost as easy as a text link would be. Perhaps cleaner, too, since you don’t mess up the text pane.

I confirm it does work, but only when called via a stamp, in v9.7.3b673. Note: I did spot and correct the stray { for a ( in the original code sample. It does not work in the current app beta that, by Murphy’s Law, I’d used to do my original test.

Odd that it only works in a stamp, but it does. That said, I note @eastgate’s comment above so whether this edge case is retained for future releases. IOW, I’d recommend not commit to a process built on this approach pending clarification of future support.