This is part 2 of a two part series on integrating Drafts with Evernote, written by Brett Kelly, author of Evernote Essentials. If you haven't already read it, start with part 1, Using Drafts with Evernote: Introduction, to get started. Get more great tips on Brett's site.
The built-in actions that ship with Drafts are just the beginning. The real power of Drafts lies in your ability to create new actions tailored to your specific needs.
An Simple Custom Action (for example)
So we have some context as we work through the intricacies of creating custom actions in Drafts, let’s make a simple one now. For simplicity’s sake, our action is going to create a note whose title is “Hi Drafts” and whose body greets us warmly before telling us the date and time the note was created, then add whatever is in our draft at the end of the note.
Open the action menu in Drafts and tap the “+” symbol at the top right of the list, then choose “Create Action.”
Give your action a name (“Evernote Test” is what I’m using):
We tell our action what to do by assigning it action steps. Tap “0 steps” to open the (currently empty) list of steps for our action, then tap “+” to add a new step.
Next, you’ll be presented with the Select Step Type menu. Since we’re working with Evernote, scroll down and tap on “Evernote” to open the step editor, which will look like this:
There are four fields available for us to edit:
- Title — this will be the title of the Evernote note that is created.
- Notebook — the Evernote notebook where the new note will be saved.
- Tags — any Evernote tags you’d like to assign to the note when it’s created.
- Content — the contents of the note
There are a couple of other options we haven’t covered yet—Write type and Template output format—but we’re going to leave those alone for now.
The current value for Title is [[time]]
. This is what Drafts calls a “template tag.” We’re going to learn more about these in a minute, but the short explanation is that template tags are placeholders for different values. [[time]]
inserts whatever the current date and time are when the action is run.
Since we want our note’s title to be “Hi Drafts”, let’s plug that in for the Title.
We’re going to leave Notebook and Tags alone for now. If Notebook is left blank, the note will be saved to your default Notebook in Evernote. If Tags is left blank, no Evernote tags will be applied to the note when it’s created.
On to Content…
As previously discussed, we want our note body to greet us and tell us the date and time before spelling out the text of the draft. Edit the Content field so it looks something like this:
You’ll notice we used our pal [[time]]
to dynamically fill in the date and time. We also used another template tag, [[draft]]
. This tag represents everything that was typed in Drafts before the action was run. We’ll see this in action in a second.
Our step is finished and so is our action. Tap “Save” at the top right to save the step, then “Action” at the top left to return to the Action editor, then “Done” to save the action.
Now, if you open the Drafts action menu, select “All” at the top of the list, then scroll to the bottom, we have our action:
Let’s test it out.
In a blank draft, type something (anything, really):
Then, run the action. If the wheels stayed on, there should be a new note in your default Evernote notebook that looks like this:
Congratulations — you just created your first custom Evernote action in Drafts. Let’s dig into the mechanics a bit more and see what other capabilities we have when creating custom actions.
Template Tags
There are several different template tags available when creating custom actions (see the complete list here; we won’t be using most of them here). Let’s talk about a few of the common ones:
[[draft]]
, who we’ve already met, represents all of the in the current draft.[[title]]
represents only the first line of the draft.[[body]]
represents everything after the first line of the draft.[[time]]
, our old pal, represents the current date and time.[[line|n]]
allows you to specify a certain line within the draft by its number. For example, if you want to do something special with line 3 of a draft, you’d use[[line|3]]
[[line|n]]
allows for some variations:
[[line|m..n]]
works just like[[line|n]]
, except this tag lets you specify a range of lines instead of a single line (i.e.,[[line|3..6]]
represents lines 3–6 of the current draft).- You can also omit the first or second value to grab everything up to or everything from a certain line:
[[line|..6]]
represents everything in the draft up to line 6 and[[line|4..]]
represents the fourth line through the end of the draft.
As you’ll see in a second, we can put these tags to some pretty iteresting uses…
Evernote Notebooks and Tags
When we created our example action earlier, we left the Notebook and Tags values blank in the step editor. This isn’t necessary, of course, so let’s update our action to define a Notebook and some tags.
We have a couple of options here: we can type in the names of the Notebook and tags we’d like to use, like so:
Or, we can employ our new friend [[line|n]]
to set the notebook and tags dynamically:
With this configuration, we can define the destination notebook and tags for the Evernote note in the body of the draft (which is pretty slick).
Using our updated action, this draft:
Ends up as this when we run our Evernote action:
Here, you can see that the tags we defined have been applied to the new note:
Note: the notebook you select—either by adding it to the action or dynamically using [[line|n]]
—must already exist in your Evernote account. If it doesn’t, the action will fail. However, you can define new tags; these will be created if they don’t already exist.
Write Types
Evernote actions (as well as several others in Drafts) allow you to define the “Write type.” Your options are Create, Append, and Prepend. Here’s what these do in an Evernote context:
- Create creates a new Evernote note.
- Append adds to the end of an existing note.
- Prepend places text at the beginning of an existing note.
Pretty straightforward. Note that, for Append and Prepend, changing the title of the note will result in a new note being created the first time the action runs.
Template Output Formats
When sending content to Evernote, your text can be formatted a few different ways. This formatting is determined by the “Template output format” option in the action editor.
Our three choices are:
- Text; this option inserts the text from your draft into Evernote exactly as it appears in Drafts.
- Markdown; as we discussed in the introduction, this option runs the text through a Markdown preprocessor before adding the resulting rich text to Evernote.
- ENML is Evernote’s markup language for notes. It’s a variant of XHTML with a few additional elements added for things like todos (checkboxes), images, embedded documents, and other files.
Since this is the first time it’s come up, let’s cover ENML in a bit more detail before we move on (this will be Drafts-specific; you can read the full ENML specification here).
Since Drafts deals exclusively in text, the only Evernote-specific ENML tag we can use is <en-todo>
, which represents a checkbox in an Evernote note.
If our Drafts action has ENML selected as the output format, we can compose our entire draft using XHTML and have it properly render in Evernote:
When using the ENML output template, this draft will look like this in Evernote:
Note: when using this output template, the contents must be valid XHTML, otherwise Evernote’s API will reject the new note as malformed. If you create a custom action using ENML that consistently fails, check the action log for the draft in question to see what’s going on. Chances are, Evernote’s API will provide a meaningful error that can help you solve the problem.
Combining Evernote with Other Actions
You might have noticed when we created our first action step earlier that the interface seemed to imply that multiple actions steps could be performed in a single action (which is true).
Let’s create a new action, with multiple steps, that does the following:
- Publishes the current draft to Twitter
- Logs the draft to a note in Evernote called “Tweet Log”
Open the action list in Drafts and tap the “+” then “Create Action.” Name your action whatever you like (I’m using “Tweet and Log to Evernote”).
Tap the Steps section, then “+” to create a new action step. Since we want to tweet our draft first, scroll down in the Step Type list and select Twitter.
In the step editor, the only thing you’ll need to do is add your Twitter account by tapping the encircled + next to Username. If Drafts doesn’t have access to your system Twitter account(s), Drafts will let you know how to give it such access:
Once you’ve added your Twitter account, click Save.
Next, tap the + to add another action step. This is where we log the tweeted text to Evernote, so select Evernote from the Step Type list.
This action will log all of our tweets in a single note, so in addition to giving the Evernote note a name (and a destination notebook, if you’d like), we need to set the Write type to “append.”
You also might want to format the output to include the date and time the text was tweeted and add a separator so it’s easy to visually distinguish between different tweets. You can do all of this by customizing the Content field:
Click Save at the top, then Action at the top left of the Action Steps list, then Done to save your new action.
That’s all there is to it. Now, if you compose a draft that’s 140 characters or less (Twitter’s maximum length for a tweet) and run the action we just made, it will be posted to Twitter and saved to Evernote.
Advanced Actions from the Directory
We talked about adding new actions from the Action Directory in the introduction, but it’s important to point out here that, in addition to using these actions, they can be modified to fit your needs.
Let’s take a user-submitted action and look at the various pieces.
This action, submitted by @rosscatrow, is designed to process a collection of meeting notes (written in Markdown); specifically, notes that contain Markdown checkboxes—sets of square brackets separated by a space for incomplete tasks or an ‘x’ for complete tasks, all preceded by a hyphen, then a space:
- [ ] This is an unchecked Markdown checkbox
- [x] This is a checked Markdown checkbox
The action takes the draft and performs the following actions:
- Convert all of the Markdown checkboxes into Evernote todos (and checking the boxes if the todo is marked as complete).
- Save the converted content of the draft to Evernote.
- Locate all incomplete todos in the draft and create a new OmniFocus task for each.
The action does this in four discrete steps:
- A Script action that converts all of the checkboxes into the ENML syntax for Evernote todos and stores the converted text as a new template tag (
evernotedraft
). - An Evernote action that saves the content of
evernotdraft
as a new note in Evernote. - Another Script action that collects all of unchecked Markdown checkboxes in the draft.
- A List in Reminders action that sends adds each of the collected tasks to a list in the Reminders app that, when everything is configured properly, OmniFocus will read for new tasks.
While you may not be up for writing JavaScript code to power your actions, you can see in this example that it’s possible to get extremely creative with what happens to your drafts.
This is part 2 of a two part series on integrating Drafts with Evernote, written by Brett Kelly, author of Evernote Essentials. If you haven't already read it, start with part 1, Using Drafts with Evernote: Introduction, to get started. Get more great tips on Brett's site.
Comments
0 comments
Please sign in to leave a comment.