IOS Automation: A Beginner’s Story

I have had the Drafts app on my iPad for some time, but haven’t used it a great deal. Recently, I decide to see how I could make more use of its capabilities.

Drafts’ raison d’être is to capture and share text with other apps. You open the app, type something and then hand it off to some other app for downstream processing. This is managed using actions. Some actions are provided, but others can be added—more on this later.

A very simple example is sending email. Open the app and a new blank draft (draft is used as the generic label for a document) appears. Type your email. Open the actions list and choose “Email”. In the standard action, you are asked to confirm the request (though this option can be changed in settings). Then the Mail app is opened. All text up to the first ↩️ is used as the subject for the email; the rest of the draft becomes the body of the email. If you have defined a signature, it will be added automatically. At this point you can choose the recipients of your mail and click [send]. You will return to Drafts.

You are not confined to simple emails as Drafts supports Markdown. If you aren’t familiar with Markdown, I urge you to take a look. It is a simple method of marking up plain text in such a way that the text is still easily readable, but when processed by an appropriate converter, it is displayed with headings, Markdownand emphases, etc., etc.—all beautifully formatted. Support for Markdown is included in many, many apps not only on iOS, but also Mac OS X, Windows and Android. There’s plenty of help on the Web for Markdown. If you’re an iBooks user, the Markdown MacSparky Field Guide is good and comprehensive.

Another standard action in Drafts will copy the text that you have formatted in Markdown to the clipboard. When the text is pasted into another application, for example, WordPress, it will appear in HTML format.

Drafts provide a number of existing actions, but also the ability to create new actions for Email, Message, Dropbox and Evernote. These are easily set up by providing a few details, selecting the odd option and possibly the use of standard tags that customise the results based on the variable data in a tag. Examples of tags are:

  • [draft]—all the text
  • [title]—the first line
  • [body]—everything, but the first line

There other tags that allow selection of specific lines in the text, and various options for date/time.

If you are a Dropbox user, you can use actions to save a draft to your folders. Settings allow you to specify path and file name (which can be picked up from the draft) and whether to create an new file or append/prepend/replace in an existing one.

Another simple action that I have found really handy is Parse to Fantastical. I use Fantastical 2 as my calendar app, even on the iPad despite the fact that it’s set up for the iPhone screen. The natural language parsing is great: Osteo next Wednesday at 11:00 for 30 mins is turned into a calendar event with no mess and no fuss. However, it’s a hell of lot easier to type this text into Drafts and run the action. Plus there’s an action that allows you to add multiple appointments at the same time. Just enter the details separated by ↩️.

Clear is another nice app that I use (almost) exclusively for shopping lists. It is not the fastest way to create a list. Now I use an action that allows me type a list into Drafts. The first line is the name of the target list. Items are then entered separated with commas. Phillip Gruneich has provided an action that works with return-separated items using Launch Center Pro, but I’m happy to enter shopping lists with commas.

Action management in Drafts allows you to specify what happens after the action has been successfully completed. You may choose to do nothing, add the draft to your archive, or simply delete it.

The Difficult Bit Puzzle

All this automation cleverness is based on URL Schemes, which I don’t propose to describe except to say that, in the same way that you can open a web page with a URL, it’s possible to open an app with a command that looks a bit like a URL. For example, clearapp:// opens the Clear app, which is somewhat useful, but limited. Here’s the action that adds items to a Clear list:

clearapp://list/create?listName=[[title]]&tasks=[[body]]

The parameters tell Clear to create or use a list that is identified by the first line of the draft, and parse the remainder—body—of the draft and add new items to the list.

Here’s a more complicated example for searching using Tweetbot:

tweetbot:///search?query=[[draft]]%20lang%3Aen%20-filter%3Aretweet%20-%22RT%20%22

Things are starting to get complicated because some characters (examples: space, colon, quotes) must be encoded in hexadecimal. This is the Parse to Fantastical action that I got from Geeks With Juniors. This shows additional complexity dealing with the results of action steps.

fantastical2://x-callback-url/parse/?
sentence=[[title]]&
x-success=
{{drafts://x-callback-url/create?
text=[[body]]&
action=Add%20Entries%20to%20Fantastical%202&
allowEmpty=NO&
afterSuccess=Delete}}&
x-cancel=
{{drafts://x-callback-url/create?
text=[[body]]&
action=Add%20Entries%20to%20Fantastical%202&
allowEmpty=NO&
afterSuccess=Delete}}

I don’t propose to explain this action in detail. It gives a further glimpse into the world of iOS automation that I’ve barely touched on. I need more time before I can write anything more than the simplest actions, but there are generous people out there who are happy to share their work with us. It is very simple to import actions from other people. They’re added to a URL Actions group that sits alongside Email and the rest. Cheater

Finally…

I’ve written this entire post in Drafts on my iPad and used an action to send it to WordPress. I did have to do some final edits in Safari. title is a keyword in both automation actions and WordPress’ email post processing, so I had to write titl to avoid parsing problems. And the handling of Markdown is not perfect, so some tidying up was required.

I think that you’ll find that Drafts and actions are worth taking time to get to know. I’ve definitely got some benefit even at my very modest level of competence.

List of Apps

These are links in the UK iTunes Store to apps I have mentioned. I’ve usually listed the iPad version, if there is one.

Drafts for iPad

Clear

Fantastical 2

Tweetbot

Launch Center Pro

Other Useful Links

Automating iOS: A Comprehensive Guide to URL Schemes and Drafts Actions is a much more comprehensive explanation than I’ve provided here.

Markdown official page on Daring Fireball.

Phillip Gruneich writes about and shares actions.

Geeks With Juniors

There are also lots of actions available on the Agile Tortoise support pages.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: