Action

Update tags…

Posted by @nahumck, Last update over 6 years ago - Unlisted

Prompt to assign or remove tags.

Steps

  • script

    // show multi-select with current assigned tags
    // and a static list of common tags
    
    // baseTags are always visible.
    var baseTags = ["d5review", "script", "GTD", "writing", "podcast", "waiting", "work"];
    
    var currentTags = draft.tags;
    var allTags = baseTags.concat(currentTags);
    var selectableTags = Array.from(new Set(allTags));
    
    // create prompt to display
    var p = Prompt.create();
    p.title = "Assign tags";
    
    p.addSelect("tags", "", selectableTags, currentTags, true);
    
    p.addTextField("othertags", "Other", "", {
      "placeholder": "comma-separated tags",
      "autocapitalization": "none"
    });
    
    p.addButton("Update");
    
    if (p.show()) {
    	var selectedTags = p.fieldValues["tags"];
       for (var tag of currentTags) {
       		draft.removeTag(tag);
       }
    	for (var tag of selectedTags) {
    		draft.addTag(tag);
    	}
    	var otherTags = p.fieldValues["othertags"].split(",");
    	for (var tag of otherTags) {
    	   draft.addTag(tag);
    	}
    	draft.update();
    }

Options

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