Tinderbox Forum

How to export to multiple text files (one per note)

I want to export about 1000 notes, so that each note becomes a stand-alone text file.

Each txt file should include the note’s $Text, prepended by the values of about a dozen attributes as attribute:value pairs, each on a separate line, with the file name being taken from the note’s $Name.

I’m reasonably confident about creating a template to pull in the attributes and $Text, but I’ve no idea how to set the export to individual txt files named by the $Title rather than to one big concatenated file.

Can anyone help with this?

Btw, I’m on Tbx v8, if that makes a difference

What you want here is to use HTML export, even though you won’t be exporting HTML!

You might begin by reading the pertinent Help pages, and/or watching a video overview of export.

The placeholder for exporting the text of a note without HTML Markup is, ^text(plain).

The placeholder for exporting the value of an attribute is ^value(attributeName)`

OK, you can do this with a single new export template; no difference for v8 vs v9 here. By default a note exported using ‘HTML’ (i.e. formatted/structured text) export uses the note $Name as the export filename. Letter case is retained but spaces, quotes, parentheses, etc. may be removed.

For the $Text, you use ^value($Text)^ which ensures no HTML gets added. For the other attributes you similarly use value. In some cases like lists/sets or date type attributes you may want to reformat the actual value.

Let’s assume we want each note to export a Number (with 2 decimal places shown), a string, unchanged, a date in you locale’s short format ( e.g. for me in UK that’s 13/07/21) using format code ‘l’ (lowercase L), and a list of $Tags values as a comma delimited list. Plus, we’ll put the attribute’s name and a colon+space before the attribute values and leave a blank line between the attributes and the text. That layout, as a template, looks like this;

MyNumber: ^value($MyNumber.format("")^
MyString; ^value($MyString)^
MyDate: ^value($MyDate.format("l"))^
Tags: ^value($Tags.format(", "))^


So, the code above is now the code we’ll paste into than export template we’ll call “text page export”).

We now have a template, and you can test how it looks by setting the template for one of your notes, showing the text pane preview selector, and selecting ‘Export’. Don’t use ‘Preview’ as we’re exporting plain text and the ‘Export’ pane will give us a cleaner view as it doesn’t try and prettify the styling of the text. Amend you template is needs be.

If unsure of how the default naming works, either use the above note or select one one whose name you think might not work well (set the template if needs be) and use menu File ▸ Export Selected Note and look to see the suggested export filename. Don’t worry about the file extension we’ll fix that in a moment.

The filename, if not calculated on the fly is stored as $HTMLExportFileName. That filename’s extension (including the period, e.g. ‘.html’ or ‘.txt’ is set via $HTMLExportExtension. The export template used for a note is stored in $HTMLExportTemplate.

You could set the template and export extension for the to-be-exported notes via:

  • an agent action
  • a prototype (or prototype(s) used via the to-be-exported notes.
  • As a document default for those attributes. I think this is not idea - use one of the above!

Mark A. – many thanks, that’s very helpful (as always!). A few tweaks later, and I’ve got it all working nicely now.

The bit that had foxed me was that I’d been trying to do the “wrapper+item” template thing on the container that held the notes, and discounted File/Export because I didn’t want to export the whole file, just these selected notes. But I see you can export everything and then just delete all the stuff you don’t need.

1 Like

Mark B. Thanks for the pointers. FWIW, I’ve been using Tbx since at least 2008 (when the file I’m working on was created), have bought and read your book at least twice, have attended the excellent Tinderbox weekend co-hosted by MarkA. in London, had searched the Forum prior to posting, and thought I was reading the right Help pages, though obviously mistaken. I used to maintain that Tinderbox export features were simply confusing to those who only use them occasionally, but clearly it’s just down to me.

BTW, I tried ^text(plain) as the placeholder but this converted e.g. an apostrophe to codes like ’ – MarkA.'s suggestion of ^value($Text)^ works much better for my purposes.

A short AppleScript makes it easy to export just selected notes to individual files.

No setup is required for each new Tinderbox document.

-- exports selected Tinderbox notes to separate text files

property fileExtension : "txt" -- can change to whatever

set theFolder to (choose folder with prompt "Choose an existing folder to receive the exported text files")
tell front document of application "Tinderbox 9"
	repeat with aNote in selections
		tell aNote
			set theFilePath to POSIX path of theFolder & (value of attribute "Name") & "." & fileExtension -- name file after note
			set theText to value of attribute "Text"
			set theTags to value of attribute "Tags"
			-- add more attributes below as desired
			set exportedContents to theText & return & theTags -- & more attributes
			do shell script "touch " & quoted form of theFilePath -- creates file if doesn't already exist
			do shell script "echo " & quoted form of exportedContents & "> " & quoted form of theFilePath
		end tell
	end repeat
end tell

  1. Copy-paste into Script Editor (in Applications > Utilities)
  2. Select notes in Tinderbox
  3. Click the “run” button in Script Editor

If “nothing happens” make sure Script Editor is listed and selected at System Preferences > Security & Privacy > Privacy > Accessibility.

I keep mine in the Script menu where it can be used “like a stamp” on notes in any Tinderbox document.

Thanks, that’s fantastic, exactly what I was originally looking for!