Tinderbox Forum

Create notes in action code using the "punch" technique

Sometimes you want to create a note using action code. Tinderbox doesn’t provide action code for creating a note directly, but you can still create notes using what I call the “punch” technique. Essentially, you use an existing note to punch a hole in the fabric of space and time Tinderbox document.

Here’s how it works:

  1. Pick a note that you will use as the “punch” note. I like to give it a specific name like tools.punch, and use it for the sole purpose of making new notes.
  2. In your action code, generate a path name for your new note. Set the punch note’s $Container to this path.
  3. At the end of your action code, reset the punch note to a known location.
  4. Run your action code!

Although Tinderbox action code doesn’t have a function for creating new notes, it will create any intermediary notes necessary to set a $Container.

Here’s a simple example (make sure you have a note named tools.punch):

$Container("tools.punch") = "/My new note";
$Container("tools.punch") = "/Tools";

And a slightly more involved example to create a dynamically-named note based on the current time:

var timestamp(date("today").format("y-M0-D h:mm"));
var newNoteLocation("/Records/" + timestamp);
$Container("tools.punch") = newNoteLocation;
$Container("tools.punch") = "/Tools";

For a working example, see the attached document. It provides two stamps that run action code – one that creates a note called “My New Note”, and another that creates a note based on the current time.

new-note-punch.tbx (59.4 KB)

1 Like

Yep, $Container tricks like these (including adding $Text to the newly created note) are things I’ve used for a long time – but judiciously. Since Eastgate has always advised “cannot create notes with code”, I’ve then assumed using $Container to make a note is (a) an unsupported “feature” and thus (b) always at risk of disappearing.

Until then, enjoy.

What other $Container are there?

right, in the code above, newNoteLocation is the path to the new note, so you can do anything with it that you’d do with any other note path.


$Text(newNoteLocation) = "my new note text"
1 Like