Basic How-To Q about exporting from TB to spreadsheet

Here is a revised script with a dialog that removes almost all the fiddliness of exporting from Tinderbox to spreadsheet while retaining flexibility.

Click to reveal revised script with 'edit the box' dialog
# Places quoted character-separated values (CSV) on clipboard for pasting wherever.
# v. 1.2 -- includes simple date conversion and "edit the box" dialog

property entryString : "Name Text NoteURL t"

set dialogText to "Export selected notes from Tinderbox to the system clipboard in a csv (character-separated value) format for pasting into spreadsheets or other applications." & return & return & "1. Select notes in Tinderbox. Non-contiguous multi levels ok." & return & return & "2. Edit the box below to choose Tinderbox attributes in the order that you want them to appear in the spreadsheet. Spell their names exactly. Add/delete/reorder as needed. Use one or more spaces between names." & return & return & "3. After the last attribute name enter one or more spaces followed by the delimiter to be used to separate items in the exported csv." & return & return & "4. Click 'Continue' to export to the clipboard for pasting. " & return & return & "                  ------------------------" & return & return & "For the delimiter enter a single character:" & return & return & "   t  for tab" & return & "   ,  for comma" & return & "   ;  for semicolon" & return & "   |  for pipe" & return & "           and so on..." & return & return & "Examples of valid entries in the box:" & return & return & "   Name MyString Path Text ," & return & "   Name MyString MyDate MySet Text ;" & return & "   Name  Text MySet MyString MyDate   ;" & return & "   Name   Text   MyString   NoteURL       t" & return

set theResponse to display dialog dialogText default answer entryString buttons {"Cancel", "Continue"} default button "Continue" with title "Tinderbox Export to Spreadsheet"

set entryString to text returned of theResponse
tell entryString
	if character -2 is not " " then error "Can't find a delimiter at end."
	set myDelimiter to last character
	if myDelimiter is "t" then set myDelimiter to tab
	set grabAttribs to words of text 1 thru -2 --if "t" present ignore as last "word"
end tell

--  NO USER TINKERING NEEDED BELOW THIS LINE, at least in theory;)

set text item delimiters to quote & myDelimiter & quote

# create separate list to hold lists of attribute values (a "list of lists")
copy grabAttribs to attribVals

set numCols to grabAttribs's length

tell application "Tinderbox 8"
	tell front document's selections -- (note use of plural)
		repeat with i from 1 to numCols
			set attrName to grabAttribs's item i
			tell attribute attrName
				# add list of this attribute's values to the list of lists
				set attribVals's item i to value
				# if attribute is date then convert format
				if item 1's kind is "date" then copy my convertDates(attribVals's item i) to attribVals's item i
			end tell
			# adds list of this attribute's values to the list of lists
		end repeat
	end tell
end tell

set numRows to attribVals's item 1's length

set outStr to quote & (grabAttribs as string) & quote & return # header row

repeat with i from 1 to numRows
	set rowItems to {}
	repeat with j from 1 to numCols
		set rowItems's end to attribVals's item j's item i
	end repeat
	set outStr to outStr & quote & (rowItems as string) & quote & return # body row
end repeat

set the clipboard to outStr

display notification "Tinderbox data ready for pasting."

--return outStr -- uncomment this line to view output in Script Editor 'Result' pane


-- handlers (subroutines)

to convertDates(listOfIsoDates)
	-- convert list of Tinderbox ISO 8601 dates to spaced date-time string for spreadsheets
	set convertedDates to {}
	repeat with i from 1 to listOfIsoDates's length
		tell listOfIsoDates's item i
			if it is "never" then
				set convertedDates's end to ""
			else
				set convertedDates's end to its text 1 thru 10 & " " & text 12 thru 19
			end if
		end tell
	end repeat
	return convertedDates
end convertDates

Just activate the Script Menu and save the script with a name like ‘Export Notes to Spreadsheet’ in the right folder. On my machine that’s Library > Scripts > Tinderbox 8. I first saved the script as usual, giving it a name. Then in Finder I held down the option key and chose Go > Library and navigated to the Script folder. I added a Tinderbox 8 folder there and dragged the script into it. (Or for keyboard shortcut access place the script in a Automator Service, a.k.a. Quick Action) or run it with a favorite third-party launcher, etc.) If placed in the Script Menu the script usually remembers the last entry in the box, making quick edits and adjustments easy.

Be sure to give permission, if asked, for the Script Menu to control Tinderbox. Permissions can be reviewed at System Preferences > Security & Privacy > Privacy > Automation. It may also be necessary to make sure Script Editor and Tinderbox 8 are listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.

This is the dialog, which also serves as a checklist of sorts when memory fails, though there isn’t much to remember.

3 Likes