Action

Change Tag

Posted by @brentacPrime, Last update almost 6 years ago

This is adapted from scripts by @mattmaybe and by @nahumck. The idea is to get a list of current tags, select one, and then pick something to replace it with. It pulls from recent tags and prompts you to select one, then to type a replacement.

Steps

  • script

    var lists = Draft.recentTags();
    
    var p = Prompt.create();
    p.title = "Tag you want to change"
    
    for (i = 0; i < lists.length; i++) {
      p.addButton(lists[i]);
    }
    
    var con = p.show();
    
    if (con) {
      var button = p.buttonPressed;
    } else {
      context.cancel();
    }
    
    const chosen = button;
    app.displayInfoMessage(button);
    
    var p = Prompt.create();
    p.title = "Enter Tags";
    p.message = "Tag to replace: " + chosen;
    var oldTag = chosen;
    p.addTextField("newTag","New Tag","");
    p.addButton("Go");
    var con = p.show();
    
    var oldTag = chosen;
    var newTag = p.fieldValues["newTag"];
    
    if (con) {
      var items = Draft.query("", "all", [oldTag])
      for (var item of items) {
        item.removeTag(oldTag);
        item.addTag(newTag);
        item.update();  
      }
    }
    else {
      context.cancel
    }

Options

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