Is there any way to get a list of current tags ?
I use a lot of tags. In order to keep my set of tags as logical and efficient as possible, I need to occasionally review existing tags, looking for redundant tags or potential gaps that require new tags. To do this, an easy way to get a list of current tags is required. Is there any way to get such a list ?
If that doesn't work, the best I can come up with is exporting to CSV and the splitting the tag column and removing duplicates, which can both be done in Excel or any scripting language -- not sure that still qualifies as simple, though.
Re the second option, I actually didn't realize that tags were included in a library/collection Export to CSV. But I agree with you that processing that output to get a non-redundant list of tags is not simple. ;)
I haven't tested this on large tag sets, but it works for small sets and automatically de-dedupes (or rather, treats the same tag as a single tag in the first place)
var rows = await Zotero.DB.queryAsync("SELECT name AS tagname, COUNT(*) AS num FROM tags JOIN itemTags USING (tagID) GROUP BY tagname ORDER BY UPPER(tagname) ASC");
var lines = [];
for (let row of rows) {
lines.push(row.tagname + '\t' + row.num);
}
return lines.join('\n');
var items = ZoteroPane.getSelectedItems();
var tagCounts = new Map();
for (let item of items) {
let tags = item.getTags();
for (let { tag } of tags) {
if (!tagCounts.has(tag)) {
tagCounts.set(tag, 1);
}
else {
let num = tagCounts.get(tag);
tagCounts.set(tag, num + 1);
}
}
}
var str = "";
for (let [tag, num] of [...tagCounts.entries()].sort()) {
str += tag + "\t" + num + "\n";
}
Zotero currently has no way to save such scripts for regular use. So just save the code to a file and copy/paste/run it as above when you need a new list.
https://github.com/windingwind/zotero-tag
This includes selecting a collection (or the whole library) then select to export tags. This generates a csv file with tags, their counts, and items titles.
Be sure to tick include sub collections if you need so (or from Zotero select: View, Show items from subcollections).
You can also import, add, remove multiple tags to multiple items using this addon (although this is done one by one and might be quite slow compared with using Zotero directly to select multiple items and drag them to one tag at a time).
Thanks!