Action

Add to ToDo List

Posted by zisoft, Last update 5 days ago

Manage multiple todo lists with Drafts.

Create one draft for each todo list you want to manage. Give this drafts the tag todolist.

Now, create a new draft with new todo text items (one per line) and select the action. You will get prompted to select one of your todo lists. The items will be appended as todo checkmarks to the selected draft.

Steps

  • script

    // Add to ToDoList Action
    // 
    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    // tag to assign to list drafts
    const todoListTag = "todolist";
    
    // grab the text from the current draft
    const currentContent = draft.content.trim();
    
    // get all drafts with the todoListTag
    let drafts = Draft.query("", "all", [todoListTag]);
    
    // prompt to select one of the todoList drafts
    let prompt = Prompt.create();
    prompt.title = "Select ToDo List Draft";
    
    for (let draft of drafts.sort((a,b) => a.displayTitle > b.displayTitle)) {
    	prompt.addButton(draft.displayTitle, draft.uuid);
    }
    
    if (prompt.show()) {
    	// user made a selection
    	
    	// uuid of the selected draft
    	let uuid = prompt.buttonPressed;
    	
    	let todoListDraft = Draft.find(uuid);
    	
    	if (todoListDraft) {
    		// append the current text as checkmarks to the selected draft
    		let lines = currentContent.split("\n");
    		
    		for (let line of lines) {
    		    todoListDraft.content += "- [ ] " + line + "\n";
    		}
    		
    		todoListDraft.update();
    	}
    }
    else { 
    	// user cancelled prompt
    	context.cancel();
    }
    

Options

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