How to automatically number note titles in Tinderbox?

I want to automatically number my note titles in order to better organize and sort my notes. For instance, I’d like my note titles to look like this:

  1. How Beautiful Life Is
  2. Sunset Boulevard

I’ve tried using the OnAdd action and the $Name attribute, but I didn’t get the desired result. Each time I add a new note, its name is set as “1. untitled”, instead of the combination of a number and the title I expect.

I think you might want to look at:

  1. $DisplayExpression, which lets you display a string that isn’t the note’s $Name
  2. $SiblingOrder, which tells you the order of the note in the outline.

So, a $DisplayExpression of $SiblingOrder+". "+$Name` might be what you’re looking for.

3 Likes

The solution found be eastgate is perfect.

A more complicated approach:

In the OnAdd action of a parent container set the prototype for each new note like in:

$Prototype="pCountNameCombo";
$ChildCountNumber=$ChildCount(parent);

And here I persist the current number of children into a custom attribute.
Now the edict of the prototype comes into play:

if(!$IsPrototype){
  if($OriginalName != $Name.replace("([0-9]+\. )+","")) {
    $OriginalName = $Name.replace("([0-9]+\. )+","");
  };
  if($Name == $Name.replace("([0-9]+\. )+","")) {
    $Name = $ChildCountNumber + ". " + $OriginalName;  
  }
};

I don’t want to change anything if there is no need to but if the name of the note changes I would like to reflect this change too. So there is a new attribute $OriginalName to preserve the name without the numbering…

But eastgates solution is much (!) more elegant!

auto_number.tbx (114.3 KB)