Action

Elixir Radar (Markdown) to OmniFocus

Posted by Robert Rainthorpe, Last update about 4 years ago

Create a Task in OmniFocus for each entry in an Elixir Radar digest

Input is a Draft resulting from calling the Elixir Radar (RTF) Email Import action
on an Elixir Radar email’s Articles section. See that action for more details of the format. Note that only the first link is used currently.

Tasks are left in the OmniFocus add window, ready for confirmation or cancellation.

See script for tags and project options.

Doesn’t support Folders for Projects, sorry.

Steps

  • script (macOS only)

    
    
    // change these as required
    const tags = "read,elixir,blogs";
    const project = "Elixir Radar Reading List";
    
    // I'm a GTD nut so I like a verb. YMMV
    const taskNamePrefix = "read ";
    
    // see: https://inside.omnifocus.com/url-schemes
    const baseURL = "omnifocus://x-callback-url/add/";
    const linkRe = /\[([^\[]+)\]\(([^\[]+)\)/;
    
    // cache for links
    var title = "";
    var link = "";
    
    // we're going to find one or more links, followed by a description.
    // cache the first link, ignore the rest
    // when we've got a description, add a Task to Omnifocus
    var lines = draft.content.split("\n");
    for (var line of lines) {
      // ignore blanks
      if (Boolean(line.trim())) {
        let result = line.match(linkRe);
    
        if (result) {
          if (title == "") {
            title = result[1];
            link = result[2];
          } // or just skip found links after first one
        } else {
          // check if we're the description
          if (title != "") {
            createOF(title, link, line);
            title = "";
            link = "";
          } // else ignore badly formatted or comment
        }
      }
    }
    
    function createOF(name, url, description) {
      var cb = CallbackURL.create();
      cb.baseURL = baseURL;
      cb.addParameter("name", taskNamePrefix + name);
      cb.addParameter("note", url + "\n\n" + description);
      cb.addParameter("tags", tags);
      cb.addParameter("project", project);
      cb.addParameter("parallel", true);
    
      // open and wait for result
      success = cb.open();
      if (success) {
        console.log("Event created");
      } else {
        // something went wrong or was cancelled
        console.log(cb.status);
        if (cb.status == "cancel") {
          context.cancel();
        } else {
          context.fail();
        }
      }
      success;
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.