Tinderbox Forum

Note (Prefix-)titel automatically?

Hi there,
I wonder, if there is any way to produce a note’s title or better a prefix automatically? I would like to start every new note’s title with an expression of the current date and time like “1902241204”, if e.g. I create the note on 24th February 2019 at 12:04 AM. Ideally this should be the prefix for the textual notes title, like “1902241204 Note’s title”. Is there any way to do so?
Kind regards,

In the notes’ prototype set $DisplayExpression to

$Created.format("YM0Dhmm")+ " " +$Name;

See this for more information on date formats.


[For later readers, the previous reply was posted whilst I was writing this one and so this is an alternative to the reply above and not in opposition to it]

You might assume the method is a Display Expression . However, in this case as you want to set a value that uses a changing value, i.e. current date time, it is probably better to use an OnAdd action:

$Name = date("today").format("YM0Dhmm");

The format string equates to two-digit-year+month+day+hour+minute, all zero-left-padded (i.e. ‘05’ not ‘5’). Thus a new note, using the above code, created as I type gives a $Name value of 1902241136. I can then select the newly formed note and type the ‘text’ part of the name. If you want the initial action to add a trailing space ready for you to type just the text, use:

$Name = date("today").format("YM0Dhmm")+" ";

It might seem more intuitive that you type the text name and the date/time is inserted. However, aside from a stamp there is no once-only action unless you add code to detect/store the date-time has been added. That all gets a bit cumbersome, compared to the OnAdd approach described above.

You can also use the same code in a stamp, should it help. Recall, a stamp runs once, on the selected note(s) and in this case would use the current date-time of the stamp’s use in setting the date-time string. Note that if you want to stamp notes with an existing text title but no date prefix, you’d use this slightly amended code:

$Name = date("today").format("YM0Dhmm")+" "+$Name;

Lastly, if you do use this OnAdd approach, I’d suggest not using the root level container as your primary workspace. IOW, especially for map-view based use, don’t work on a new doc’s default map but make a container and use the child map of the container as your ‘main’ map. Why? The OnAdd in the root view is the document. Thus you’d be setting the OnAdd default for the entire document. It might be what you want but experience makes me doubt it.

Indeed, a general tip. For long-lived documents, as opposed to just testing or experimenting, I’d strongly advise putting your data (whatever: observations, addresses, commentary notes, etc.) in a container at root level. This way your ‘data’, i.e. the main information you may want to query, is automatically kept separate from containers for prototype, templates, and general back-of-house stuff. This helps with agents and actions. In my experience, anyway…

Many thanks for your quick help. I just tested the onAdd solution and the result is, what I am looking for, because I would like to have the title and not only the display name with this prefix. I would prefer the “stamp” solution, because this title should not be changed after moving the item for example. I just found the menu item “stamps” and how to use it. Many thanks.

I which case change the OnAdd to use a |= operator (see more) instead of a =:

$Name |= date("today").format("YM0Dhmm");

Thank you. Unfortunately it isn’t working on my side, maybe because every new note open with “untitled”, by dragging a note with an empty title it works.

1 Like

Ah - this is due to the timing of the setting of Name. sorry, wasn’t replying from my Mac so couldn’t test.

@PaulWalters’ solution should work for you. A reminder of his code above:

$Created.format("YM0Dhmm")+ " " +$Name;

As $Created stores the date-time of the note’s creation (i.e. same as date("now") at that time) making a new note within your container or moving a note created elsewhere into the container will stay correct. An edge case, if you make a note outside your container and move it into the container a week later, the date-time will be a week out of date in terms of the date in the new container; this might be problematic for your filing purposes. Unfortunately, you can’t edit $Created (as it’s a read-only value). The fix is simple - don’t make new notes in containers that don’t have the correct OnAdd in them.

No problem, the help from you both is appreciate and many, many thanks to you, Mark and Paul. The “stamp”-solution works very well for me. By adding

$Created.format(“YM0Dhmm”)+ " " +$Name;

to the “onAdd” field also only an “untitled” notes open by create one. But nevertheless I can use the stamp. In fact I am nearly a beginner with TB and maybe I have not enough experience with this great tool to set up your suggestions corrrectly. But for now the stamp will do.
Again, many, many thanks to you both.
And kindest regards from Germany.

1 Like