Things Parser for Drafts 5

UPDATE: I’ve just released a version 2.0 of my Drafts Parser with new block-based entry and project creation features. You can read more about the update here.

I’ve had a lot of fun lately playing around with the beta of Drafts 5. The developer Greg Pierce of Agile Tortoise has been hard at work on a number of new features, notably developing and expanding the possibilities for JavaScript automation within the app. If you can pick up some JavaScript, there are some very powerful new things you can now do.

For example, I wrote a script to automatically add Markdown Links in reference style, complete with clipboard URL detection and automatically incrementing link reference numbers. You can add it to Drafts from the Drafts 5 Action Directory here.

Recently, I was reading Federico Viticci’s fanstastic article on MacStories about Things automation. The Cultured Code team have recently updated Things with an advanced new URL scheme. In addition to a lot of new URL scheme actions, they added an add-json command which allows you to import a bunch of tasks or projects into Things with a single URL scheme action: no jumping back and forth between apps with repeated x-callback-URLs. Federico created a workflow which takes the content of the clipboard copied from a text editor, and assembles a chunk of JSON to send to Things. Each line of the text becomes a separate task, with special characters giving additional metadata about each task.

As part of its new scripting features, Drafts 5 added integration (via JavaScript) with this new add-json action, so this got me thinking about whether I could recreate Federico’s idea directly in JavaScript within Drafts.1 What I have ended up creating is a script which is completely compatible with his syntax, but expands upon it and makes it little more flexible.

First of all, it removes the need for the double backslash before the date and time of the event. I’ve built this script on top of a bit of JavaScript called Chrono. It’s a natural language parser that works for multiple languages and can detect references to dates automatically within a string. This means you can write things like “Tomorrow” or “Tuesday” anywhere in the line and it will pick that out as the day for the task. In addition, it will automatically set a reminder if (but only if) a time is also included.

In addition, I wanted my script to support all of the features that the Things add-json command supports, so as well as the special markup characters for projects, headings, tags, and notes, I’ve added characters for deadlines and checklist items. The full syntax is as follows:

  • #Project Name
  • ==Heading
  • @Tag Name
  • ++Note
  • !Deadline
  • *Checklist item

As with tag names in Federico’s workflow, multiple checklist items can be entered.

With this Drafts action, I can type multiple lines in the following format, and they are all simultaneously sent to the right place in Things.

Write blog post about Drafts and Things today at 4pm #Writing ==PolyMaths @drafts @things !Friday *drink espresso *write *publish

If you’re a Drafts user and want to use this script, you can only do so if you are on the Drafts 5 beta. If not, the full release of Drafts 5 should be coming soon, so watch out for that.

You can see my script here, and you can add it as action in Drafts by downloading it from the Drafts 5 Action Directory here.

  1. Of course, it is very simple to create an action that launches Federico’s workflow directly from within Drafts. Drafts has a native “Run Workflow” action step which you can use.