Tinderbox Forum

Getting text of children in a note

I’m trying something that I think I have done in a simple way in the past… but forgot how to do it!

I would like to have as text in a note the text of it’s children.


In the action field of a prototype should do it, no? But it doesn’t work. What I’m missing?

thanks in advance!


You are really close! Attributes are case-sensitive, so you’d want to use $Text instead of $text in your action code.

How are you by the way? How’s the script writing going?

1 Like

Thanks, Michael. I was laughing alone, how could I forget it? But then I correct it and… it’s not working.

Maybe I can do something to find what is preventing the action code to work?

I’m fine, writing a new script and, as usual, evolving my template for it.

Here go, try this. Note, I added in a .replace to get linked breaks between the children text.

TBX L - CollectChildrenText.tbx (91.0 KB)

It’s working. thanks!

And your addition is great. But I can’t make it work. I still get a “;” between the texts of each note in the parent note.

Another question. If I want to gather all the texts in a hierarchy of notes, I should replace “children” by descendants, no?

If you are using the code as in @satikusala’s TBX’s “Collect Children” stamp:


Without being able to see the code causing your mistake, the likely cause is you omitting the .replace() step.

In the demo file above, we have 3 notes with respective Text: " Note 4 Text.", “Note 2 Text.”, and Note 3 Text.".
Using a stamp like below on Note:


creates $Text of:

Note 4 Text.;Note 2 Text.;Note 3 Text.

Why? Because collect() returns a list of value as List-type data. Lists and Set data are essentially a String but with a semi-colon between each list item. Thus if $MyList contains values “A”, “B” and “C”, it is stored as the string A;B;C.

Sure enough when we pass the output of collect() to $Text, is is like doing an action:

$MyList = collect(children,$Text);
$Text = $MyList;

This forces Tinderbox to ask, what do I do with List data? As it is essentially a string, $Text now holds the literal stored string content of the list.

The point of the format("formatString") us to tell Tinderbox, give me the list with the list delimiters (the semicolons) replaced by the characters in the formatString argument. The most common list-to-string choices are ", " for a coma+space list, e.g. “A, B, C” or “\n” where each item becomes a separate line/paragraph as in:


It is the latter one (.format("\n") that I think you want, as used in @satikusala’s demo above.

Thanks a lot, mark, for the class! If one day, maybe, I’ll be able to write expressions, it’s thanks to this forum.

I think I have done a mess editing directly the action code of the notes. I chose a note that was "untouched’ used the stamp and it worked.

Last question. If I apply the stamp to a prototype, it should propagate to all notes using this prototype, no?

I inserted it as an action in the prototype. It doesn’t work.

But when I stamp the note with the same code, it works…

No! Because of several things:

  • Although the stamp changes the $Text of the prototype, a prototype’s $Text is only inherited when the prototype is first applied to a note. Subsequent changes to text are not inherited.
  • If a note already has $Text when a prototype is assigned, the prototype’s $Text is not inherited.

If you want to apply this functionality to a prototype use an edict (a rule would be overkill and edicts can be run on demand if needed):

  • Select the prototype and open the Edict Inspector.
  • First set $EdictDisabled to false by unticking the enabled box at bottom left.
    • Why? Because you don’t want the edict running on the prototype itself and generating likely unwanted $Text.
  • Paste your (functioning) stamp code into the Edict code box and press Return. You have now set the code for $Edict.

Now, any note using this prototype will inherit an edict that periodically sets that note’s $Text as a list of that note’s child note titles ($Name)

By ‘action’ I guess you set the prototype’s $OnAdd (‘Action’ tab). As the OnAdd acts on new child notes, it isn’t what you want. You need to use a rule or as suggested above, an Edict.

If I’ve misunderstood, just ask! :slight_smile:

Great, Mark! It works perfectly. Thanks!

1 Like