Fixing Recursive Workflows with the New allowEmpty Parameter in Drafts 3.5.4

A couple of days ago, Greg Pierce released a new update to Drafts. The 3.5.4 update has a quick fix for text encoding bug found in the previous update. What makes the previous 3.5.3 update a noteworthy one is the new allowEmpty=[YES/NO] parameter for executing incoming URLs.

Incoming URL is a way for Drafts and other apps to create a new draft, execute a named action, or import a new custom action in Drafts. I've been using it to perform recursive invocations on custom URL actions. My earliest example was adding multiple events in Fantastical, which dated back in April.

Unfortunately, the September's 3.5 update included a feature that conflicts with the recursive hacks I've been using. The new feature allows you to run actions on an empty draft, regardless whether it's manually triggered or triggered by an incoming URL. This forced me to come up with a workaround that removed the x-cancel parameter as the only way to stop the infinite loop when the other app doesn't prompt you whether you want to continue or not.

I've also come up with another workaround that uses a runtime value, instead of a predefined value, for the action parameter. This allows recursive actions that only involve Drafts to stop when it encounters a blank action name. It's great for triggering multiple built-in Drafts actions with a single draft, or for importing a batch of URL actions recursively.

The new allowEmpty=[YES/NO] parameter solves this recursive problem. Because most recursive invocations are incoming URLs, we can set the allowEmpty parameter to NO. This stops the recursive invocation whenever it encounters an empty draft. It also frees us to use x-cancel parameter the way we want to, whether we want to cancel and return, or cancel and continue.

The perfect example for this update is the first example that started this recursive hack in the first place: adding multiple events in Fantastical. It was Fantastical's 1.1.1 update with x-callback-url that started it all. And with the new Fantastical 2 released yesterday, it's only appropriate if I update it with the new fantastical2:// URL Scheme.

Read More

How to Chain Any Combination of Built-in Drafts Actions without Writing New Custom Actions

Drafts 3.5 is a great update to an already amazing app. My favorite feature is, of course, the new ".." range feature in [[line|n]] tag. For example, with [[line|4..]] tag, I can easily select all entries from the fourth line to the end of the draft and use it as the email body in my Mail Later action.

Open this link if you want it installed on your iOS device automatically.

Phillip Gruneich has recently shown that you can use the [[line|..2]] tag to send more information recursively to another app. We're no longer limited to selecting a single line for recursive actions.

Today, I want to highlight how I've been using the new range feature to chain any combination of built-in Drafts actions easily without having to write a new URL action for each combination.

Using a single action, I can define at runtime how I want the first three lines of my draft to be crossposted to any number of services.

The Motivation

By now, you probably know me as someone who loves to create his own custom URL actions that chains two or more apps using the x-callback-url specification. Even though I enjoy creating them, oftentimes I find it too limiting because the order and the number of actions that I want to chain are pretty much static and limited to the ones I describe in the action. I've always wanted to have a way to easily define what I want to chain at runtime, instead of at coding time.

For example, I may write a 140-character draft that I want to crosspost to multiple Twitter accounts, my App.net account, my Facebook account, log it to a Dropbox file or an Evernote note, send it as both an iMessage and an email to multiple recipients in my circle of friends. Even though I can create a very long chain of actions to do all of the above, I sometimes want to do a simple crosspost to Twitter and App.net only. Other times, I want to share it on Facebook and email only. It would be great if I could write an action that can handle this:

[Something worthy of a tweet]
Tweet: epramono
Tweet: geekwithjunior
Post to App.net
Post to Facebook
Post to Google+ (public)

or this:

[A short journal entry]
Dropbox Action: My son's logbook
Post to Facebook

or this:

[A must-read link for my circle of friends]
Post to Google+ (circle)
Email Action: Friends
Message Action: Friends

I dream of one action to rule them all: an action that allows me to chain an arbitrary number of built-in Drafts actions, defined at runtime, on the same set of lines.

Read More

Troubleshooting Tips for Recursive Actions in Drafts 3.5

Prior to last week, I have extensively used recursive technique to invoke custom URL actions in Drafts processing each line into an event in Fantastical, a reminder in Due, or a Pomodoro task in Due. With the latest Drafts 3.5 update, this technique can cause an infinite loop because Drafts allows actions to run on an empty draft.

For actions that involve Due, I'd suggest you to stop returning to Drafts on your last reminder or task. But for the "Add Events to Fantastical" action, this trick doesn't work. Unlike Due, Fantastical doesn't prompt you before returning to Drafts.

Until I come up with a better solution, or until Greg Pierce decides to add a new feature that can avoid this problem, I will remove the x-cancel parameter of the "Add Events to Fantastical" action. At least, now you can stop the infinite loop by tapping the Cancel button on Fantastical parsing window.

Read More

Workflow: Add Daily Medication Reminders in Due using Drafts

I have been enjoying Due over the past three weeks. I really like the app. Not just because it's really fast to load and has a great natural language processing support, but mainly because it has a great support for x-callback-url.

This is an example of the common use case I have for jotting down multiple reminders in a single seating using Drafts.

Adding Multiple Reminders to Due

The most obvious use case for me is to create a custom URL action in Drafts to add multiple reminders with a single post. I named the new action Add Reminders to Due:

due://x-callback-url/add?title=[[title]]&x-source=Drafts&x-cancel={{drafts://x-callback-url/create?text=[[body]]&action=Add%20Reminders%20to%20Due&afterSuccess=Delete}}&x-success={{drafts://x-callback-url/create?text=[[body]]&action=Add%20Reminders%20to%20Due&afterSuccess=Delete}}

Open this link if you want it installed on your iOS device automatically. If you want to learn more about the technique I used here, please refer to my previous workflow on adding multiple events to Fantastical.

If this is the first time you use an x-callback-url to add reminders to Due, you need to understand that you need to manually tap the title bar in Due twice for each reminder. The first tap is required to set the date and time of the reminder. The second tap is optional. If you tap them, the date/time information will be removed from the title, otherwise it will stay as is.

Once the reminder has been added, Due will show a popup asking you for a permission to go back to Drafts, according to the x-success parameter. If you don't allow it, the chain of actions stops immediately.

Read More

Workflow: Create Multiple Events in Fantastical with Recursive Action in Drafts

One of the things I commonly do several times a day is registering new events in Fantastical. Sometimes, I even created multiple events in a single seating. I need to find a way to easily write any number of these events down in Drafts and have them processed through Fantastical automatically.

This is an example of the common use case I have for jotting down multiple events in a single seating using Drafts.

In order to do this, I need to parse each line in the Drafts post and convert it to a Fantastical URL scheme. Because I don't know how many events I want to create each time I trigger this action, I need the action to recursively invoke itself until there are no more lines left.

Read More