Save to OneNote & Create Omnifocus Tasks

Last update 6 months ago

Save to timestamped note in the “Drafts” section of your default OneNote notebook along with Omnifocus Tasks from lines that begin with [ ]

Updated to include Drafts callback url in OmniFocus notes field.

Steps

  • onenote

    notebook
    section
    Drafts
    page
    [[time]]
    template
    [[draft]]
    format
    markdown
    writeType
    create
  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    // Start every line with [ ] to denote it as a task
    
    const taskPrefix = "[ ]";
    
    
    // Function to perform the callback url
    function doCallbackURL(url, params) {
      var cb = CallbackURL.create();
      cb.baseURL = url;
    
      for(var key in params) {
       cb.addParameter(key, params[key]);
      }
    
      var success = cb.open();
      if (success) {
        console.log("Event created");
      } else {
        console.log(cb.status);
        if (cb.status == "cancel") {
          context.cancel();
        } else {
          context.fail();
        }
      }
    }
    
    // Scan for the task prefix in the draft
    var lines = draft.content.split("\n");
    
    for (var line of lines) {
      // If the line includes the task prefix, 
      // we remove exclude it from the final notes
      if (line.startsWith(taskPrefix)) {
    
        // Remove the trigger from the line
        var task = line.replace("[ ]","");
        task = task.trim();
    
        var alink = draft.permalink;
       
        doCallbackURL("omnifocus:///add", {"name": task, "note": alink, "target": "inbox", "autosave": true});
     }
    }
    

Options

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