Tinderbox and Drafts (getdrafts.com)

Now that there’s a pretty solid macOS version of Drafts (https://getdrafts.com/), I’m wondering if anyone has has any experience with Drafts and Tinderbox integration?

Drafts provides similar scripting chops to Tinderbox, and also creates UUID for each individual Draft in its storage. It seems a natural place to start notes for Tinderbox, using the great iOS version of Drafts, which can then be exploded or split into a glut of Tinderbox notes on the macOS side.

Before I sacrifice a vast quantity of time into this rabbit hole, I’m wondering if braver people than I have stepped in there already?

1 Like

In the sense that Teslas are like tricycles, I suppose :slight_smile:

There are numerous scripts already posted here by @trewr and others that could easily be incorporated in a Drafts action.

I haven’t looked at macOS drafts, but my impression (perhaps out of date ?) was that it didn’t include the JavaScript actions of the iOS version.

Has that now changed ?

( TaskPaper has a richer JS interface, including programmatic access to outline structures and key-value pairs – both of which make it a very useful adjunct to Tinderbox )

Hey Rob,

Yes, it’s changed, quite significantly. The JS model from iOS drafts has made it to the macOS version, and even the drag-and-drop automation has been ported over, naturally with limits where iOS features don’t have macOS parity. Coupled with the impressively fast syncing, it’s quite a powerhouse; it looks like it’s almost itching for the kind of Tinderbox integration that DEVONthink enjoys, particularly as it seems so much better a place to pull text from (and maybe even push to) than Simplenote or Apple Notes - even more so for Tinderbox, as it’s otherwise a plain text environment.

Might be worth another look if you’ve been away for more than six months; it’s a really impressive system, but requires a subscription for full action editing access.

3 Likes

The following AppleScript-based Drafts action will send notes from Drafts to an inbox folder in a TBX file. Tags in Drafts.app are transferred to $Tags in TBX.

-- incorporate this script in a 2-step action in Drafts.app. The action must be initiated from a note in Drafts.app with selected text that will become the $Name of the TBX note. 
-- the script is the 2nd action. The first is a Clipboard action to push SelectedText into the clipboard

on execute(draft)
	set theFile to "/path/to/TBX/file/filename.tbx"

	set theTitle to the clipboard
	
	set theBody to the content of the draft
	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, "; ")
	
	tell application "Tinderbox 8"
		open theFile
		
		tell front document
			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 theBody
				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 "KeyAttributes" to "Created;Modified;Tags"
			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
5 Likes

Nifty!

I would love to see tighter Drafts integration with Tinderbox along the lines of what DT3 can do. I suspect it would require a much richer AppleScript library, but I can talk to Drafts’ developer about that. (“Watch Drafts Workspace” would be freaking amazing)

1 Like

Yes please!

Having some way of designating a channel for notes from Drafts to get into Tinderbox would be very useful.

I don’t know what form this would eventually take, but e.g. being able to say “this TBX doc will watch for Drafts tags matching #foo”, etc. would be one way.

Drafts is on my menu bar in iOS, and has a global shortcut on my Mac. It’s exactly what the the website proclaims: where text starts. It’s by far the best tool I’ve found for quickly jotting an idea - launch the app, and a blank note pad is waiting. I use it all day, every day.

Getting stuff out of Drafts, I do the simplest way possible: I copy the text from Drafts and paste it to where it needs to go. I’ve experimented with the export options but found I just never needed them. Experience has shown me that moving text from Drafts to other apps is not the bottleneck. Drafts neatly solves the problem of “where do I put this thing?” and from there I treat it like an ordinary inbox, working through it sequentially and doing my work in other apps.

1 Like

midas0441Thanks for this. As I’m new to AppleScript and drafts it took me a bit to figure this out. For those that are also new, here are the steps that I took.

  1. Download drafts
  2. Join the 7 day free trial (afterward: $19.99/year or $1.99/mon) so that I could try the script
  3. Open drafts and create a first draft, e.g. body “My first note”, add a couple of tabs, e.g. TBX and Test.
  4. Select Managed Actions… option from the Actions menu in drafts
  5. Click the “+” button on the button left to create a new action group, name it “Add to Tinderbox”
  6. Click the “+” button on the right in the Actions list and name it “Send to Tinderbox”
  7. Double click on “Send to Tinderbox” to edit it
  8. In the bottom middle of the screen, under Steps select “Clipboard” and then the + button
  9. In the bottom middle of the screen, under Steps select “Run Apple Script” and then the + button
  10. Paste the AppleScript from the forum post to the Script field in Drafts
  11. Find you Tinderbox file in you Finder. Click on it. On the bottom of the Finder look at the path, rt. mouse click on the file name and click “Copy ‘[FileName]’ as Pathname”
  12. Paste the path into the AppleScript in the “set theFile” line
  13. Open Drafts and select Show Action list form the View menu
  14. In the search bar search for Tinderbox
  15. Click on the note you want to send to Tinderbox and double click on the action “Send to Tinderbox” action you create (the first time macOS will ask for permissions)

You’ll hear a beep and the draft note will have been added to your Tinderbox.

3 Likes

Just have Drafts put the note on the clipboard, then paste it to the Outline.

(I’m always harping on the fact that scripting is often the sledgehammer approach to solving problems – explore the simpler options first. In the case, above, someone would have to modify – and test, always test – the script for each new document. )

2 Likes

Paul, you’re right in that this will work for the drafts note body, but it is not clear to me how the process could work for populating the tags, title, and other attributes. Perhaps the Drafts templated to make this work. Not sure.

I didn’t say it would.

HI @midas0441, love this script. I do have a question and could use your help (@sumnerg, maybe you have an idea).

When I use this script the $Name of the note in Tinderbox becomes the ensure body of my Drafts note. Is there a way that I can adjust the Apple Script so the $Name of the not is the first line of the Drafts file? I’d love to learn Apple Script to make the change myself, but I don’t know where to start.

I don’t use Drafts so can’t test but it will probably work by replacing

set theTitle to the clipboard

with

set theTitle to paragraph 1 of (the clipboard)
2 Likes

You’re a genius!!! Worked perfectly.

Do you have a recommended resource for learning how to write Apple Script?

2 Likes

Nope. I‘ve started by modifying scripts. That was far from ideal.

Here are some things that could be useful.

How to get started with writing AppleScript

  • Don’t modify existing scripts.
    Read and try to understand the steps taken in a script, then start writing your own.

  • Do use descriptive variable names.
    Using self-explanatory variable names makes it easier for you to understand what your script does while writing it and in the future. It also makes it easier for other users, e.g. when you post one that you need help with. You’ll often find variable names used in someone else’s script cryptic or not descriptive enough. Change these to your own when you write your script.

  • Do use comments.
    -- or # in front of a line comments it out. Use them to deactivate code while testing something or to add your comments.

  • Start every script with a short description of the desired outcome.

How to get started with searching

  • Use e.g. startpage.com to search for AppleScript plus the command or idea you have.

    • Do not rapidly scan search results
      Even if a result doesn’t seem to answer your current question there’s a value in reading it. This way I’ve found countless things I didn’t know were possible.
    • Do not skip results that seem to rely on an app you don’t use.
      There’s value in reading them too. See above.
    • Capture what could someday be of interest.
      Create a group in DEVONthink and simply store everything in it. Use a searchable format, e.g. webarchive.
  • Searching in an app’s forum is different.

    • Don’t search for AppleScript.
      In my experience most posts that include an AppleScript do not contain the term “AppleScript”. Instead you’ll find posts of users asking for a script.
    • Do search for something that’s part of almost all scripts, e.g. tell application

How to get started with understanding what happens in a script

  • Download Script Debugger.

  • Read Script Debugger’s help.

  • Use Script Debugger’s Results & Variables Tab

  • Try

  • Try

  • Try

:slight_smile:

2 Likes

Definite +1 for Script Debugger if doing more than tinkering. does what it says in the app name. I use it occasionally, but it’s a real help when I do use it.

1 Like

There is also Sal Soghoian and Bill Cheeseman book “AppleScript 1-2-3” and Matt Neuburg “AppleScript The Definitive Guide”

1 Like

Rosenthal’s “AppleScript” (pub. Apress) has also been useful. This and the books above have all been out a while so can likely be picked up for very little money from somewhere like abebooks.com.

The forums at MacScripter have also been helpful along the way, especially for old hands to helpfully confirm that some things that ought to work just don’t (but there there’s usually an alternative approach).

2 Likes