Action

Add new obsidian tasks

Posted by mandli, Last update about 4 hours ago

Add tasks to obsidian master task list as specified. Will add check boxes if necessary and skip blank lines. Also allows you to add a tag if you want. Uses the advanced URI plugin and does not wait for a callback.

Steps

  • script

    const vault_name = "notes";
    const task_file = "tasks/master"; // Note that the '/' is encoded directly
    const tag = "#todo"
    var lines = draft.content.split("\n");
    var output = "";
    
    for (var line of lines) {
    	// Parse line, add checkbox if not present
    	if (line.trim().length == 0) {
    		continue; // Skip empty lines
    	} else if (line.trim().replace("-", "").length == 0) {
    		continue; // Skip lines with only dashes
    	} else if (line.trim().startsWith("- [ ]") ||
    		line.trim().startsWith("- [x]") ||
    		line.trim().startsWith("- [X]")) {
    		line = line.trim(); // Keep existing checkbox
    	} else {
    		line = "- [ ] " + line.trim(); // Add checkbox
    	}
    	if (output.length > 0) {
    		output = output + "\n" + line + " " + tag; // Append to output
    	} else {
    		output = line + " " + tag; // Initialize output
    	}
    }
    output = output + "\n";
    
    // Create callback URL
    let cb = CallbackURL.create();
    cb.baseURL = "obsidian://adv-uri";
    cb.addParameter("vault", vault_name);
    cb.addParameter("filename", task_file);
    cb.addParameter("mode", "prepend");
    cb.addParameter("data", output);
    cb.addParameter("separator", "");
    cb.waitForResponse = false;
    console.log(output)
    console.log(cb.url);
    
    // Use callback
    cb.open();

Options

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