Tinderbox Forum

Tinderbox Training Video 63- Export Drafts Note to Tinderbox

Tinderbox Training Video 63- Export Drafts Note to Tinderbox

Level Intermediate
Published Date 12/22/21
Revision 2
Acknowledgement @midas0441 wrote the base Apple Script and @webline has done a tone to refine it
Revision History 23DEC12: Added 30 sec to video that was cut off, made note about Tinderbox 8 support
Type Now To
Tags 4Cs of Knowledge Management and Exchange, 5CKMEl, Apple Script, Drafts App, Tinderbox, aTbRef
Video Length 13:20
Video URL https://youtu.be/WThZmPPMx3s
Example File TBX L - Export Drafts Note to Tinderbox.tbx (130.6 KB)
TBX Version 8.9+*
Instructor Michael Becker

In this lesson, I explain how to export notes crated in Drafts to Tinderbox. I demonstrate the process and explain how to set up the export action in Drafts. I also explain how to edit the attributes statements in the Apple Script within Drafts to suit your own purposes. For example, I show how you can apply your own prototypes to the exported notes, or change the mapping of the Drafts URI to whatever URL attribute you want. Finally, I demonstrate how note writing in markdown in Drafts works perfectly in Tinderbox.

TBX L- Export Drafts Notes to Tinderbox

Note for Tinderbox 8 Users

*Note: If you are still using Tinderbox 8 this process will work, however, you’ll want to change the app reference that the Apple Script in Drafts is calling. You’ll want to edit the tell application "Tinderbox 9" reference, change the 9 to an 8.


1 Like

Great video! I look forward to integrating this into my workflow.
Two brief remarks:

  1. The video seems to be cut short at the end - it stops mid sentence.
  2. The TBX version is given as 8.9 when 9.1 seems more likely.

Ah, yes. Thanks. I’m trying to learn Adobe Premier, still working out the kinks. 30 seconds got cut off. Here you go: https://youtu.be/WThZmPPMx3s.

As for point 2, it is 8.9+, this will work with older versions of Tinderbox. I should have noted in the video that if you’re on Tinderbox 8 you’ll wan to change the app name that the Apple Script is calling from 9 to 8.

or use

tell application id "Cere"

to open the installed version of TBX - ignoring the version.

1 Like

I saw that you created the notes in the frontmost window in TBX - I paste the notes into a dedicated file - so here is an update to the Drafts action to choose the target with a dialog (this way you could ask for other details for the new note too):

-- The action must be initiated from a note in Drafts.app while the title of the note will become the $Name of the TBX note. 
-- the script is based on the work of midas0441 (TBX forum)

on execute(draft)
    -- adjust the filename and path to your personal file
	set theTBXFile to "/Users/yourname/Documents/Tinderbox/ideas.tbx"

	set theTitle to title of the draft
	set theFullBody to the content of the draft
    set theCleanBody to returnContentWithoutFirstLine(theFullBody)
 	set theCreateDate to ("" & createdAt of the draft)
	set theModifyDate to ("" & modifiedAt of the draft)
	set theTags to (tags of the draft)
	set theListOfTags to convertListToString(theTags, "; ")
    set theLinkToDrafts to the permalink of the draft

	set theDialogText to "Store to your default file or the frontmost file?"
	display dialog theDialogText buttons {"Frontmost", "Default"} default button "Default" with icon caution giving up after 5
	if the button returned of the result is "Frontmost" then
		set theTarget to false
		set theTarget to true
	end if

	tell application id "Cere"
		if theTarget then
			open theTBXFile
		end if
		tell front document
			if not (exists note "Inbox") then make new note with properties {name:"Inbox"}
			set theContainer to note "inbox"
			set myNote to make new note with properties {name:theTitle} at theContainer
			tell myNote
				set value of attribute "Text" to theCleanBody
				set value of attribute "Created" to theCreateDate
				set value of attribute "Modified" to theModifyDate
				set value of attribute "Tags" to theListOfTags
				set value of attribute "Prototype" to "pNotiz aus Drafts"
				set value of attribute "URL" to theLinkToDrafts
				set value of attribute "DisplayedAttributes" to "Created;Modified;Tags;URL"
			end tell
		end tell
	end tell
end execute

on convertListToString(theList, theDelimiter)
	set AppleScript's text item delimiters to theDelimiter
	set theString to theList as string
	set AppleScript's text item delimiters to ""
	return theString
end convertListToString

on returnContentWithoutFirstLine(allContent)
	set theResult to ""
	set theFirstNonEmptyLine to returnTheFirstNonEmptyLine(allContent)
	set text item delimiters to return
	set theResult to (paragraphs theFirstNonEmptyLine thru -1) of allContent as string
	set text item delimiters to ""

	return theResult
end returnContentWithoutFirstLine

on returnTheFirstNonEmptyLine(allContent)
	set theResult to 2
	repeat with i from 2 to the number of paragraphs in allContent
		if paragraph i of allContent is not "" then
			set theResult to i
			exit repeat
		end if
	end repeat

	return theResult
end returnTheFirstNonEmptyLine

even easier to install the action into Drafts - open the URL and click the “Install” button and you are ready to go: AddToTinderbox | Drafts Directory

Is that what ID “Cere” means?

this is internal ID of the Tinderbox app - it’s an alternative way to call the app.

(“The code name for the Tinderbox project, prior to release of Tinderbox 1.0, was ‘Ceres’.” by MB)

1 Like

I removed this line because I always get and error like this:

Is see now that this requires a change in the file path. Cool.

One note, in your new script, in the Inbox does not already exist in the default file I get an error with the script.

fixed the script above :wink:

1 Like

Cool, did not know this. BTE, is it “Cere” or “Ceres”. It seams on “Cere” works, but in the note above it says “Ceres”.

only four letters available - so it has to be “Cere”

1 Like

What did you change?

inbox will be created if missing:

if not (exists note "Inbox") then make new note with properties {name:"Inbox"}

Yes, I understand that…I wanted to see the code bit. Not sure what code you changed.

Thanks for this, @satikusala and @webline, very useful. I love markdown but prefer rich text in Tinderbox. Is there an easy way to convert the markdown text in Drafts to Rich Text as part of this action? I have a Drafts add-on which copies the text as Rich but am not clear how that might be combined into the action.

Can you try it? Maybe nothing special needs to be done.

You’re welcome, BTW.

@satikusala, I tried inserting the script for the rich text copy both before and after the existing scripts, but no difference: the result remains markdown.

there is no option to extract the text as RTF - the only solution I found is converting the text to html and copy this: Markdown to Notes | Drafts Directory
Or you may insert this into the TBX action - converts the markdown in Drafts into HTML.
Keyboard Majestro may be another way to go or use AppleScript to store the content in a temp file, open this file with Marked 2 (via AppleScript), convert it to RTF and copy the result into TBX. Sounds more complex then it is :wink:

One other option for RTF would be to export from Drafts to DEVON instead of directly into Tinderbox, then have a smart rule (or manual conversion) to convert to RTF in DEVON. This is done fairly seamlessly. Then drag and drop into Tinderbox as you wish. Just another option to think about. I use DEVON to store all my notes and pdf and then use Tinderbox to explore deeper. This workflow works well if you use a similar workflow.

1 Like

Thanks, @webline and @TomD, i’ll try both those ideas!