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 ?
  • I assume you're aware of the tag selector on the bottom left? If you're in "My Library" that shows all tags, alphabetically (with colored tags on top).

    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.
  • Thanks for those suggestions. But I have too many tags for just looking in the tag selector box to be viable. If however there was an option to right-click Select All tags (or a subset) in that box, and then Copy to the clipboard, that would work. So I guess that's a feature request.

    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. ;)
  • One option is to select all the items in the library, export to CSV, and then open the exported file in a spreadsheet program like Excel. Tags are one column of that file, so you can search and sort from there
  • (I do suggest that above, but you still need to de-dupe, so this is some work)
  • If however there was an option to right-click Select All tags (or a subset) in that box, and then Copy to the clipboard, that would work.
    Turns out that the Zutilo add-on can actually do this: select all items in the middle panel (or select those for which you are interested in the tags), then right-click --> Zutilo --> Copy tags to clipboard.
    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)
  • Thanks ! Zutilo worked well and quickly, for a collection with ~3000 items and 150+ tags. Pasted from clipboard into Excel for alphabetical sort.
  • Decided to further address this with some javascript, adding a count of how often each tag has been used. Run under Tools\Developer\Run Javascript:

    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');
  • @tim820 Your Javascript is exactly what I needed! Thank you!
  • @tim820 (or others)... how would you modify this .js to act only on the currently-selected items?
  • 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";
    }
  • Hi all, I am trying to do the same thing, i.e. copy an extensive list of all individual tags in a large library. I've installed the Zutilo add-on but it still doesn't let me select all tags in the bottom left hand pane. Any advice please? I don't know how to use Java script.
  • edited July 18, 2023
    @ARC79 you simply copy/paste either of the code scripts above into the box under Tools\Developer\Run Javascript in Zotero. Then click Run. You should get a list of tags in the right box. Copy and paste that list into a file if you want to keep it.

    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.
  • You can also use the Zotero-tag add-on to mass-manage tags.
    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).
  • I'm looking for a way to export _defined_ tags, not just tags in use.
  • I found a somewhat clumsy solution to the problem I posed: not of dumping tags currently in use against your bibliography, but tags defined. I run OSX, so I have a copy of Shottr, a screen shot utility. It has an OCR function that is reasonably effective against a rectangular piece of the screen you choose---the tag cloud in this case. It is only effective up to a certain volume---I ended up slicing the tag cloud into 20/25 line rows with three or four tags each. They end up on the clipboard, so you can paste / accumlate them into a text editor. The process misses a certain number of underbars (which I normally use to connect terms) so some subsequent manual curation is needed.
  • edited September 26, 2023
    @lcgillies: This sounds like a misunderstanding. Tags in use and tags defined are the same thing in Zotero. It's not possible to have tags that aren't associated with any items. It would be much easier to just use one of the code snippets or plugins above.
  • @tim820 Thanks for that .js , but could you help me adjust the code so that I can retrieve only tags from all records within ONE collection (or subcollection)? by showing where in the original code such an amendment can be made? I'm writing a systematic literature review and want to isolate tags by subcollection *preferably cross referenced to a particular record article so I can make a frequency distribution (duplicates help in my research, ironically!). Any help would be super appreciated before I kill a lot of time manually typing...

    Thanks!
  • @s1968258 you could do that with @dstillman 's code above, by first selecting all items in the collection you want tags from: select collection, select any item, Ctrl-A to select all items, then run the code to get the tag list. You can also run it on any or all selected items in the Duplicate Items collection, or on selected adjacent title-sorted items (that are duplicates) in a regular collection.
  • Wow @tim820 thank you so much. Worked like a charm! Lastly -- is there any way to link those codes to their respect publications?
Sign In or Register to comment.