Extract Text from an XML File Using Launch Center Pro, Drafts, and TextTool

Tweet This Post

Paperless is an iOS lists app that stores its data in XML files in Dropbox (if you choose to sync). What follows is an attempt to procure the first item in a list and send it to Due without having to copy and paste.

The first list item in any Paperless list appears to occur on line 12 of the list's XML file. It looks like this:

<itemName>LIST ITEM</itemName>

Launch Center Pro's dropbox tag lets you get the contents of a text file, so I figured I could grab the entire contents of an XML file and push it to Drafts. Tap on this link to import into LCP, or copy the action below and adapt for your purposes:

drafts://x-callback-url/create?text=[dropbox-text:Paperless/Errands.xml]&action=line12

What this does is grab the full text from the Errands list in Paperless, send it to Drafts, and then activate the line12 custom URL action.

line12 uses a Drafts tag [[line|12]] to send line 12 of the XML file to TextTool and then use the regex method to replace <itemName> and </itemName> with blank spaces. I know next to nothing about regex, but I found here that I could easily create a regex expression to match both <itemName> and </itemName>:

<(/|)itemName>

So the search parameter in TextTool is the above URL-encoded, and the replace parameter is a single space, URL-encoded:

texttool://x-callback-url/transform?text=[[line|12]]&method=regex&search=%3C(%2F%7C)itemName%3E&replace=%20&x-success=due%3A%2F%2Fx-callback-url%2Fadd%3Ftitle%3D%5B%5Boutput%5D%5D

(Tap on this link to import into Drafts.)

The x-success parameter above tells TextTool to take the [[output]] of that transformation and send it to Due. Here is that action URL-decoded:

due://x-callback-url/add?title=[[output]]

The final result... I tap on the LCP action, and it adds the first list item from my Errands list and sends it to Due. There are spaces preceding the text, but the XML is extracted.

Although the automation required to perform the above is a bit excessive (in contrast to just copying an item from Paperless and then pasting it into Due) it demonstrates the ability of the included iOS apps to accomplish pretty remarkable tasks.

 

Addendum (2014-02-04)

Here is an importable line12 Drafts action that trims the TextTool regex output before it sends the list item to Due. And here is the URL action itself:

texttool://x-callback-url/transform?text=[[line|12]]&method=regex&search=%3C(%2F%7C)itemName%3E&replace=%20&x-success=texttool%3A%2F%2Fx-callback-url%2Ftransform%3Ftext%3D%5B%5Boutput%5D%5D%26method%3Dtrim%26x-success%3Ddue%253A%252F%252Fx-callback-url%252Fadd%253Ftitle%253D%25255B%25255Boutput%25255D%25255D

 

Addendum 2 (2014-02-04)

Here is an importable line12 Drafts action that will include a link to the Errands list in Paperless within the Due text, so that when you complete the task, you can visit the list and check off the item there. (Thanks to @epramono for inspiring this.) And here is the URL action itself:

texttool://x-callback-url/transform?text=[[line|12]]&method=regex&search=%3C(%2F%7C)itemName%3E&replace=%20&x-success=texttool%3A%2F%2Fx-callback-url%2Ftransform%3Ftext%3D%5B%5Boutput%5D%5D%26method%3Dtrim%26x-success%3Ddue%253A%252F%252Fx-callback-url%252Fadd%253Ftitle%253D%25255B%25255Boutput%25255D%25255D%25250Apaperless%25253A%25252F%25252FviewList%25253FlistName%25253DErrands

Last built: Mon, May 12, 2014 at 8:52 AM

By Jeffrey Kishner, Monday, February 3, 2014 at 12:47 PM.