Use a Recursive URL Action in Drafts for iOS to Create a Public Note in Dropbox and Tweet a Link to That Note

The x-callback-url spec allows apps to communicate with each other, and takes URL schemes to another level. My first exposure to URL schemes was via Launch Center Pro, which enables you to to, for example, enter prompts within the app and then send this text to Omnifocus to automatically create a new task with a note.

omnifocus:///add?name=[prompt]&note=[prompt]

 
The callback lets you take yet another action, like return to an app (more possibilities below). In a previous post, I outline how I composed the following to send the contents of the clipboard from LCP to Drafts to Dropbox and then return to LCP:

drafts://x-callback-url/create?text=[clipboard]&action=Save%20to%20Dropbox&x-success=launchpro%3A

 
To summarize: I entered this URL in the Action Composer in Launch Center Pro. When I tap on the action, it takes the contents of the clipboard and sends it to Drafts. It then performs the action Save to Dropbox and after that has been successfully completed, it returns me to Launch Center Pro.

You can even perform a second action with text, not just launch another app. Here, Federico Viticci at MacStories posts to App.net and then Twitter:

drafts://x-callback-url/create?text=[[draft]]&action=Post%20to%20App.net&x-success=tweetbot://viticci/post?text=[[draft]]

 
He URL-encodes Drafts’ Post to App.net action (essentially converting spaces to %20) and upon the success of that action, he uses the URL scheme for Tweetbot to use the exact same text (signified by [[draft]]).

URL Encoding to Perform a Second Drafts URL Action

The recently-updated v2.5.3 of Drafts for iPhone allows you to embed text in {{ }} to URL-encode it:

Values in double curly brackets “{{value}}” in URL and Dropbox Action templates will be URL encoded. This is helpful when constructing complicated URL Actions with callbacks or other paramters [sic], so, for example you can type an x-callback-url x-success parameter as “x-success={{http://targeturl.com}}” and not have to manually encode the special characters.

@viticci and @chewingpencils have been playing around with Drafts URL Actions in which Drafts calls back itself after it has completed an action. This is an interesting form of recursion in which, instead of having another app perform an action after the success of the first action, a new URL action within Drafts is performed.

Here are a couple of examples by @chewingpencils:

Following this pattern, I have created an URL Action (which I call create and tweet public note) that creates a note in my Public dropbox folder and then tweets the title and URL of that note via Tweetbot.

drafts://x-callback-url/create?text=[[draft]]&action={{Public Note}}&x-success={{drafts://x-callback-url/create?text=[[draft]]&action=tweet%20public%20note}}

 
The Public Note is just a Dropbox Action that uses the first line as the title and puts a new note at /Public/imissmymac/. If you’re on your iPhone, tap this link to import the action into your version of Drafts. (I’ve removed the /imissmymac/ subdirectory from this importable action.)

The complicated part is autogenerating a link to that note. I know that the URL of my Public folder is http://dl.dropbox.com/u/14977279/. I figured out that you can URL-encode template placeholders to keep them URL-encoded:

tweetbot://imissmymac/post?text=[[title]]%20http://dl.dropbox.com/u/14977279/imissmymac/{{[[title]]}}.txt

 
The above URL Action (which I’ve called tweet public note in the URL Action above) sends the URL-encoded first line to tweetbot, which decodes it into regular text ([[title]]). I follow it with an URL-encoded space (%20), and then the URL for my Public Dropbox folder and \imissmymac\ subdirectory. I then tell Drafts to keep the first line URL-encoded ({{[[title]]}}), and follow it with the file extension (.txt).

The result: if the first line of my draft is Check out this note, Drafts will autogenerate the following in Tweetbot:

Check out this note http://dl.dropbox.com/u/14977279/imissmymac/Check%20out%20this%20note.txt

 


There are multiple varations on the above theme. For example, the iPhone app Notebooks uses the following URL scheme to open specific notes: notebooks://show/Note.txt (for the root Notebook). I can create a note in Notebooks via a Dropbox action and then add a link to it from a task management app using that app’s URL scheme. Please share your own variations in the comments or on Twitter.

Speak Your Mind

*