Action

Rename Tag...

Posted by agiletortoise, Last update almost 4 years ago

Utility action which will find all drafts with a particular tag, remove that tag and add another tag in it’s place, effectively renaming the tag. The action can also be used to completely delete a tag, by leaving the new tag option blank.

Steps

  • script

    // prompt for old and new tag and re-assign all instances of the first tag to the new one
    let p = Prompt.create();
    p.title = "Rename Tag"
    p.message = "Enter old and new tag names. All drafts assigned the old tag will have that tag removed and the new tag added. Leave the new tag blank to simply remove all assignments of the old tag."
    
    p.addTextField("oldTag", "Old tag", "", {
    	"placeholder": "existing tag",
    	"autocorrect": false,
    	"autocapitalization": "none",
    	"wantsFocus": true
    });
    p.addTextField("newTag", "New tag", "", {
    	"placeholder": "tag to assign",
    	"autocorrect": false,
    	"autocapitalization": "none",
    	"wantsFocus": true
    });
    
    p.addButton("Rename Tag");
    
    if (p.show()) {
    	let oldTag = p.fieldValues["oldTag"];
    	let newTag = p.fieldValues["newTag"];
    
    	let drafts = Draft.query("", "all", [oldTag]);
    	if (drafts.length == 0) {
    		alert("No drafts with tag \"" + oldTag + "\" found.");
    	}
    	else {
    		let ct = 0;
    		for (let d of drafts) {
    			d.removeTag(oldTag);
    			if (newTag.length > 0) {
    				d.addTag(newTag);
    			}
    			d.update();
    			ct++;
    		}
    		alert(ct + " draft(s) updated.");
    	}
    }

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.