Action

2Do Project

Posted by @kerim, Last update almost 6 years ago

This drafts action finds all uncompleted markdown tasks in a draft and sends them to 2Do as sub-tasks of a single project in your inbox, using the title of the draft as the project title.

Steps

  • script

    // 2Do Project
    // This drafts action finds all uncompleted markdown tasks in a draft and sends them to 2Do as sub-tasks of a single project in your inbox, using the title of the draft as the project title.
    // https://actions.getdrafts.com/a/1Qx
    
    // define stuff
    const baseURL = "twodo://x-callback-url/paste";
    let theTitle = draft.processTemplate("[[safe_title]]");
    var taskList = theTitle;
    taskList += "\n";
    var content = editor.getText();
    
    
    // loop content
    var lines = content.split("\n");
    
    for (var line of lines) {
    	if (line.startsWith("- [ ]")) {
    		task = line.replace("- [ ]", "").trim();
    		taskList += "    " + task + "\n";
    	}
    }
    
    // paste to 2do
    if (taskList.length) {
       var cb = CallbackURL.create();
    	cb.baseURL = baseURL;
    	cb.addParameter("text", taskList);
    	cb.addParameter("forlist", "Inbox");
    	var success = cb.open();
    	if (success) {
    		console.log("Tasks created in 2Do");
    	} else {
    		context.fail();
    	}
    }
    

Options

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