Convert a List to OPML for Fargo with Drafts

I’ve been using Dave Winer’s new outliner product Fargo frequently, yet I often initially enter my ideas into Drafts for iOS. Fargo works with OPML files, but if you copy a list into it (even one with tab indents), Fargo will maintain the structure, creating a new node (or “headline”) for each line and even making the tab-intended lines “children” of the main line above them.

The Problem: how to get my list in Drafts into Fargo with the least amount of effort?

It’s possible to just send the entire list to a text file in Dropbox, then access that file on the desktop, copy it, and paste it into Fargo. But there’s a better way. Inspired by Alex Guyot’s work on chopping a draft, I’ve composed a five (!) Drafts actions that let me convert a text list of any length into an OPML file that I can import into Fargo. The key to this solution is an URL Action that works as an infinite loop, in which the following occurs:

  • Take first line of draft ([[title]]) and use it to create the opening of the OPML file.
  • Take the rest of the list ([[body]]) and create a new draft with it.
  • Take the first line of the new draft and append it as an outline node to the OPML file I just created.
  • Take the rest of the list ([[body]]) and create a new draft with it.
  • Repeat those previous two steps ad infinitum until the loop is closed, i.e., we’re left with an empty draft.
  • Then close the OPML file with the final line from the list and the closing tags.

Caveats

This solution will work if you are not using HTML or links containing &s. If you are using HTML, you will have to encode it, e.g., <b>bold</b> is &lt;b&gt;bold&lt;/b&gt;.

This solution will not work with tab-indented lists, i.e., each item in the list will be a main headline. You can indent the outline once you’re in Fargo.

Step 1: the OPML-START URL Action

If you’re on your iOS device, tap on this link to import the URL Action. Or you can create your own, titled opml-start:

drafts://x-callback-url/create?text=[[title]]&action=opml-header&x-success={{drafts://x-callback-url/create?text=[[body]]&action=opml-loop}}

 
This action takes the first line ([[title]]) and calls the opml-header Dropbox action, which we will create below. It then takes all list items below the first line ([[body]]), creates a new draft with this text, and calls the URL action opml-loop.

Step 2: the OPML-HEADER Dropbox Action

Tap on this link or do the following:

  • Create a dropbox Action called opml-header
  • The path should be where your Fargo files are: /Apps/Fargo/
  • The filename is predefined as [[date]]
  • The extension is opml
  • Set “write” to append.

In the template put the following:

<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>[[draft]]</title>
</head>
<body>
<outline text="[[draft]]" />

 
The reason the file uses the date stamp is that, since we will be performing many actions appending to the same file, the title needs to remain something that is non-variable. We cannot use [[title]] because the first line is different every time we create a new draft. However, we can put the first line of our list in the header title for the OPML file. This is what will show up in the tab section in Fargo.

Note: If you perform this list-to-OPML action more than once daily, you will need to change the filename of the first import so that it is not overwritten. Or you can use the [[date|...]] tag to include, say, the hour as well. If the minute changes while you are doing this conversion, there is a risk that two different files will be created, so I advise against creating too-specific a timestamp.

Step 3: the OPML-LOOP URL Action

Tap on this link to import the URL Action, or manually create one titled opml-loop and enter the following:

drafts://x-callback-url/create?text=[[title]]&action={{opml-body}}&x-success={{drafts://x-callback-url/create?text=[[body]]&action=opml-loop}}

 
This action starts on the second line of your list — which is now the first line of the new draft — and takes the opml-body action, which appends the line within <outline text="" /> to the OPML file. Then it takes the rest of the list, creates a new draft with it, and initiates the opml-loop action. You’ll note that the opml-loop action calls upon itself after successfully adding the first line of the remaining list to the body of the OPML file. This action will run on each line of your list until there’s nothing left, at which time Drafts will display a red alert. This recursive process of extracting the first line of the list, appending it to the file, extracting the first line of the remaining list, appending it to the file, and so on until it ends is what makes this whole solution possible.

Step 4: the OPML-BODY Dropbox Action

Tap on this link to import the action, or create a Dropbox Action titled opml-body. Use the same exact settings as for the previous Dropbox Action ([[date]] as the title, append, the same file path, opml extension) and enter the following as the template:

<outline text="[[draft]]" />

 
Every time this action is called, the first line of the remaining list gets added in proper OPML format to the OPML file.

Step 5: the OPML-END Dropbox Action

Tap on this link to import the action, or create a new Dropbox action called opml-end with all the same settings, and put the following in the template:

<outline text="[[draft]]" />
</body>
</opml>

 

Finally, Ready to Take Action!

The only real kink in this solution 1 is that the opml-end action has to be manually initiated after the opml-loop ends (i.e., when you get the red alert). To make this work, first create a text list with an item on each line:

About Me
My name is Jeffrey Kishner
I blog at imissmymac.com
I love outlining

 
Then cut the last line so that it’s in your clipboard.

About Me
My name is Jeffrey Kishner
I blog at imissmymac.com

 
Tap on the opml-start action and let it run its course. (By default, you’re going to have a whole lot of drafts unless you play around with the delete/archive settings for the actions).

Once you’ve received the red alert, paste the clipboard contents into a new draft, and tap on opml-end.

In my example, there will be text file titled something like 2013-05-10.opml in my Fargo folder, containing the following:

<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>About Me</title>
</head>
<body>
<outline text="About Me" />
<outline text="My name is Jeffrey Kishner" />
<outline text="I blog at imissmymac.com" />
<outline text="I love outlining" />
</body>
</opml>

 
I can then go into Fargo, import this file, and see the following under a tab titled About Me:

Fargo

In Conclusion

If you’re willing to import 5 Drafts actions, then this set-up process requires little effort on your part. If you’re thinking, Why in heaven would anyone go through all this effort just to convert a list into OPML? then you’re probably in the wrong place. This solution is a proof-of-concept inspired by Alex Guyot and solves a problem I’ve had as a Fargo user who dumps my ideas in my iPhone. I am totally open to more elegant solutions, please leave a comment below or send me a tweet.


  1. Until Drafts can take action on an empty draft, and the x-error parameter can be used to take the final action. 

Speak Your Mind

*