$OnAdd linkTo(children)?

Hi,

I have a note called “Top”, I add children notes named “uno”, “dos” and “tres”
Using the $OnAdd action, I was hoping to have Top automatically create a link to the children notes.

Here is my $OnAdd action code for the “Top” parent note.

linkTo(children)

Its not not working and I am not sure why?

Thanks in advance,
Tom

The OnAdd code is run on the new children. You are asking them to link to their (non-existent!) children.

You want to look at something like linkFrom(scope[, linkTypeStr]). In v9.5.2, this code in $OnAdd makes a basic [sic] untyped link from the container to the new child:

linkFrom(parent);
1 Like

Ahh, I was thinking it was running on the parent and not the children. Your explanation makes perfect sense now. Code works perfectly.

Thank you, Mark.

Tom

OnAdd runs once per child note when:

  • an existing note is moved to the current container, either via manual drag or via action code.
  • a new note is created as a child of the current container (eve if it is the first child to be created for a note that isn’t yet a container)

Little used, but there, is an OnRemove action too. It runs, unsurprisingly, on a child note when it is removed from the current container. Note: deleting a child note is not a removal event as there is nothing upon which to act.

1 Like

A listing of events (Action-type system attributes) is here; Action-Type Attributes.

Note some are mainly there for compatibility with other apps as opposed to being intentional Tinderbox events.

I noticed MarkB mentioned yesterday, the $OnVisit is also now in Tinderbox.
Are you planning on adding it to aTBRef?

Tom

As in OnVisit?

Where are you looking in aTbRef and not finding these pages?

That’s not snark, I’m just genuinely confused at how people can’t find things like the above and wondering what i’m doing wrong. Is it a terminology mis-match?

You are right! not sure how I missed it. right there in front of my eyes. I missed it.
ATBRef is indispensible. I use it everyday and learn something, each and every day!

Thanks Mark for your incredible dedication.

Tom

1 Like

Just as a side question - are the square brackets a misspelling there? I know it shows like that in TBX help as well. However, the formula works without them and the first one is in an odd place before comma.

the [square brackets] are an, unofficial, standard notation in code documentation. Anything in square brackets is optional, i.e. you don’t have to use it.

Thus you can generate a link from ‘Note A’ with no link type (i.e. type is ‘untitled’):

linkFrom("Note A");

Or, to the same but with a type ‘explains’:

linkFrom("Note A", "explains");

As, in a default document there is not per-defined type ‘explains’, this is also added to the documents’s defined link type.

It’s simply not possible to document in detail, every variation in every context. For instance, aTbRef expects the reader, if they don’t already know, what scope implies or else follow links that explain it. So informed they will understand why only one of these uses quotes:

linkFrom("note A");
linkFrom(children); // designator names are not quoted
1 Like

This reminds me that the ‘convention’ re square brackets isn’t explained. So, if you don’t know, how would you guess.

I’ll try and add something likely in this area. If nothing else I can link to the explanation should this question arise again.

1 Like

Give us a hint, what is the convention?

It’s not a “conversion”, it’s a “convention” — an implicit agreement.

This derives from early Bell Labs Unix documentation, and so it probably stems from Brian Kernighan and P. J. Plauger. In this case, we might write

linkFrom(what [, linkType] )

to say that you can use linkFrom in two ways:

linkFrom(what , linkType )

or, if you’re happy without a link type, just

linkFrom(what )

1 Like

Sorry, auto-correct caught me.