This Week's Sponsor:

Kolide

Ensures that if a device isn’t secure it can’t access your apps.  It’s Device Trust for Okta.


Using Drafts Line Tags with URL Schemes and Actions

Drafts line tags

Drafts line tags

In a minor 3.0.6 update released last night, developer Greg Pierce added an interesting new feature to Drafts that will come in handy to further customize the app’s powerful URL, Dropbox, and Evernote actions. In the new version of Drafts (both for iPhone and iPad), you can now specify line numbers as template tags.

Tags act as variables to dynamically insert text into a draft: the app has supported shortcuts for dates, timestamps, system clipboard, and body of a draft for quite a while now, but it lacked a way to break content into lines. In older versions, Drafts could only differentiate between the entire note, the first line, or everything after the first line; there was no way to tell the app to treat, for instance, the second line and fifth line differently. This resulted in the creation of advanced workflows that used Drafts as a launcher for text and integrated with Pythonista to split text into lines, sending them separately to other apps that could receive multiple parameters via URL scheme. An example (that I also linked to here on the site) involved sending multiple tasks to OmniFocus’ Mail Drop by splitting lines written in Drafts.

With Drafts 3.0.6, you have complete control over the lines of your draft through a simple [[line|n]] format, where n is the number of the line. Using [[line|1]] will tell Drafts to use the first line, [[line|3]] the third one, and so forth; line tags can be integrated in URL actions and default fields of Evernote and Dropbox actions, such as Title, Tags, or Notebook.

To demonstrate the possibilities opened by line tags, I tweaked two of my existing workflows to take advantage of them. While both workflows were possible before Drafts 3.0.6, they have been enhanced by the addition of line tags and they now work more precisely, adding less cruft to the app’s output.

The first action, built for Safari for iPad, takes the URL and title of the current webpage, its selected text, and sends everything to Drafts through a bookmarklet:

javascript:window.location='drafts://x-callback-url/create?text='+encodeURIComponent(document.title+'\n')+encodeURIComponent(location.href+'\n')+encodeURIComponent(window.getSelection())+'&action=EvSelection&x-success='+encodeURIComponent(location.href);

In Drafts, I want to send this information to Evernote and save it as a new note in my Inbox. With line tags, I can properly split the data I have (URL, title, selection) across the required fields without having to repeat the webpage’s title in the draft – I want the title to be the title of my new Evernote note, and the note itself to only contain the URL and selection. I want the URL to be clickable, and the selection to be a blockquote.

Drafts line tags

Drafts line tags

Once sent from Safari, my draft will be structured as follows:

Line 1: Webpage title
Line 2: Webpage URL
Line 3: Selected text

In Drafts, I created an Evernote action (called “EvSelection”, as referenced by the bookmarklet) that will create an Evernote note using line 1 as Title, and line 2 + line 3 as template. I added a > character before line 3, which combined with the “Send as Markdown HTML” option will ensure I will receive a blockquote instead of regularly formatted text (and, the URL will be made clickable as well).

With this action, I can go from the following draft:

Drafts line tags

Drafts line tags

To an Evernote note in my Inbox, which used line numbers to assign the correct values to the fields I wanted:

Drafts line tags

Drafts line tags

As you can see above, the bookmarklet also tells Drafts to automatically go back to Safari after the action has run thanks to x-callback-url.

The second action shows how individual line tags can be useful for apps that support incoming information with different parameters. Quotebook, a great app to store quotes and sync them with iCloud, comes with a URL scheme that accepts data for a quote, author, source, and rating. That’s the perfect candidate for a Drafts URL action that uses line tags to let you compose a quote and send it to Quotebook while preserving the information entered on separate lines.

Drafts line tags

Drafts line tags

Whether you’re copying text from Safari, Pocket, or a tweet, it’s easy to enter text on separate lines in Drafts, then send it to Quotebook and find your quote properly formatted, without having to interact with any additional menu or popover.

Drafts line tags

Drafts line tags

Drafts line tags

Drafts line tags

And if, for some reason, you don’t want to send text directly to Quotebook from Mr. Reader, you can build a custom service that sends quotes, author details, and source to Drafts on multiple lines (a variation of this).

Drafts line tags

Drafts line tags

Last night’s Drafts update brought other fixes and improvements (like the addition of “modified” and “created” tags), but, for me, line tags are the biggest addition. I’ve long relied on Pythonista to handle line-splitting, and it’s good to see Drafts is now natively supporting this feature, which is flexible enough to be integrated in a variety of existing workflows (like the ones I described above, perhaps something like this, and more). If you’re looking for more examples of how to integrate Drafts’ line tags in your iOS workflows, Sean Korzdorfer has posted details of his Fantastical and Quotebook actions.

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.