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.
One thing I wish it did was only pull from Current/Active tags but I could not figure out how to do that (assuming it’s possible). I assume operator error, so if you know how, please feel free to share. And of course, any general improvements I would like to see too.
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;
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
}