How to delete tags in bulk?
There are a large number of tabs on the current tab bar, and it would be very troublesome for me to delete them one by one. Is there a way to delete the tabs in bulk? (I couldn't find the answer in the user manual ).
Looking forward to the answer, thank you!
Looking forward to the answer, thank you!
--------
I think I've worked out how to remove all tags from your library by combining advice from various threads without needing to use code;
1. If you have tags you want to keep, create a new collection (e.g. I named mine 'Saving coloured tags' < create a new folder for each tag you want to keep < copy all references with that tag into their specific folder.
2. Install the Zutilo plugin; https://github.com/wshanks/Zutilo (full installation instructions are on the webpage if you scroll down)
3. As is_PengLu has said at https://forums.zotero.org/discussion/comment/406821#Comment_406821 , "After installation of Zutilo, go to Tools < Zutilo Preference < User Interface < Remove tags [second option down] --> deselect 'hide' and select 'Zutilo context menu' so that 'Remove tags' will display when you right click an item
4. OPTIONAL: on the zutilo preferences menu (Tools < Zutilo preferences) click on the 'Shortcuts' tab on the top, scroll down to find 'Remove tags', select it, and enter a keyboard shortcut (I did Shift+R): this will enable you to remove all tags for the selected item(s) by pressing Shift+R
5. Go back to the main zotero window and select 'My Library' (Brown folder). Click Command+A to select all items, then Shift+R (or right click < Zutilo < Remove all tags) to remove all tags in your library
6. Reinstate the tags you saved by going back to that new collection you made in step 1 ('saving coloured tags') and add back the tags to each reference in those subfolders. You can quickly add the same tag back to a list of items by draging a set of items to a tag in the tag selector on the left (as per https://forums.zotero.org/discussion/64065/tagging-multiple-items-at-once)
This seems to have worked for me at removing the hundreds of useless tags imported from EndNote and has synced across my desktop and laptop fine. Hope that helps!
--------
Also ensure you've deselected 'autogenerate tags' to stop new tags being generated that you don't want. Instructions on how to do this are at the bottom of https://www.zotero.org/support/collections_and_tags (briefly; Edit < Preferences < General < Miscellaneous < deselect 'automatically tag items with keywords and subject headings' )
Install Actions & Tags Plugin, https://github.com/windingwind/zotero-actions-tags.
Go to the main Zotero Meny and open:
Zotero / Preferences / Actions & Tags / Actions / Add a new action (+ button)
Edit selected action (3rd button)
In the Edit Action window:
Name: Delete tags, Event: None (or Open File), Operation : Script,
Menu Label: Delete tags
Tick all boxes, Enabled etc.
Open the Data field window for editing paste and save:
// Delete tags, based on Replace tags @author windingwind
(async () => {
let targetItems = items || (item ? [item] : []);
Zotero.alert(null, "Delete all tags");
for (const currentItem of targetItems) {
const tags = currentItem.getTags().map(tag => tag.tag)
for (const tag of tags) {
currentItem.removeTag(tag)
}
}
})();
Select all items in MyLibrary, Cmd-A (mac) or Ctrl-A (windows)
Then open items Menu / Target Action / Delete items
thank you so much for the tutorial and code snippet, it helped me a lot <3
Here is a modified code which allows you to specify a list of tags that will not be deleted. I've also added annotations to make it easier to understand.
// Delete tags, based on Replace tags
// This script removes all tags from the specified Zotero items, except those in the ignore list.
// add tags you wish to keep to `ignoreTags` list, the list is prefilled with two examples
(async () => {
const ignoreTags = ['Important article', 'Reviewed'];
// ^^^^^ Add tag names here to ignore. ^^^^^^^
// Initialize `targetItems` to the array of `items`, or if `items` is undefined,
// use the single `item` wrapped in an array. If neither exists, default to an empty array.
let targetItems = items || (item ? [item] : []);
// Show an alert message
await Zotero.alert(null, "Delete all tags except ignored ones");
// Iterate over each item in the `targetItems` array.
for (const currentItem of targetItems) {
// Retrieve all tags associated with the current item.
// Use `.getTags()` to get tag objects, and map to their `tag` property to get tag names.
const tags = currentItem.getTags().map(tag => tag.tag);
// Iterate over each tag in the list of tag names.
for (const tag of tags) {
// Check if the tag is in the ignore list.
if (ignoreTags.includes(tag)) {
// Alert the user that the tag is being skipped.
await Zotero.alert(null, `Tag "${tag}" is in the ignore list and will not be deleted.`);
continue;
}
// Remove the tag from the current item using `.removeTag()`.
await currentItem.removeTag(tag);
}
}
// The script finishes here.
})();