Drafts Action Directory

Add to List

Posted by @FlohGro, Last update 30 days ago

Opens a dialog to select the list Where you warnt to Add the content of the current draft.
you Clan create a new list if you want

Install

Steps

  • script

    // add to list
    // tag to assign to list drafts
    const listTag = "ref_list";
    
    
    // grab text
    const currentContent = draft.content.trim();
    
    /////////
    var res;
    {
    let ws = Workspace.create();
    ws.tagFilter = listTag;
    ws.tagFilterRequireAll = true;
    res = ws.query("all");
    }
    res.sort((a,b) => (a.title.toUpperCase() > b.title.toUpperCase()) ? 1:-1);
    var listTitles = [];
    var p = Prompt.create();
    
    for(i in res)
    {
    	p.addButton(res[i].title,res[i].uuid);
    	listTitles.push(res[i].title);
    }
    p.addButton("CREATE NEW LIST");
    
    showSelectPrompt:
    var didSelect = p.show();
    if (didSelect == 1) {
    	if(p.buttonPressed != "CREATE NEW LIST")
    	{
    		var selecteduuid = p.buttonPressed;
    		var selectedDraft = Draft.find((selecteduuid));
    	} else {
    		var pN = Prompt.create();
    		pN.title = "create new list";
    		pN.message = "set title for new list";
    		pN.addTextField("setTitle", "set title","",[autocorrect=false, autocapitalization="words", keyboard="default",wantsFocus=true]);
    		pN.addButton("set title");
    		if(pN.show()){
    			if(pN.buttonPressed == "set title"){
    				var newListCategory = pN.fieldValues["setTitle"];
    				if (newListCategory != "") {
    					if(listTitles.includes(newListCategory)){
    						alert("list already exists, restart action and select the right list!");
    						context.cancel("user selected already existing list!")					} else {
    					var selectedDraft = Draft.create();
    					selectedDraft.content = "# " + newListCategory + "\n\n";
    					selectedDraft.languageGrammar = "Simple List";
    					}
    				} else {
    					alert("you must set a title, aborting!");
    					context.cancel("no title specified");
    				}
    			} else {
    				context.cancel("user cancelled title input");
    			}	
    		}
    	}
    
    
    var category = selectedDraft.title;
    
    var d;
    if (selectedDraft.content.startsWith("# " + category)) {
    			d = selectedDraft;
    } // else {
    
    //}
    
    d.addTag(listTag);
    d.content = d.content + "- [ ] " + currentContent + "\n"
    d.update();
    
    editor.load(d);
    } else {
    context.cancel("user cancelled add to list");
    }

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.