Skip to content

Instantly share code, notes, and snippets.

@KalebNyquist
Created August 8, 2021 21:44
Show Gist options
  • Save KalebNyquist/2ca3ac322751578b6d791cd90b4df15b to your computer and use it in GitHub Desktop.
Save KalebNyquist/2ca3ac322751578b6d791cd90b4df15b to your computer and use it in GitHub Desktop.
One of my frustrations with Zotero is that there is no easy way to list all the collections in which a file is stored. This is my band-aid of a solution. The code can be run under Tools > Developer > Run Javascript using "Sync" mode.
// Instructions:
// (1) Highlight file of interest.
// (2) Run code in Zotero's JavaScript console (found under Tools > Developer > Run Javascript) in sync mode.
function collections_output() {
zp = Zotero.getActiveZoteroPane()
items = zp.getSelectedItems()
collection_ids = items[0]["_collections"]
collections_cache = Zotero.Collections._objectCache
return_string = items[0]["_displayTitle"]
return_string += "\n\nCollections: \n"
for (i = 0; i < collection_ids.length; i++) {
return_string += "("
return_string += i+1
return_string += ") "
return_string += collections_cache[collection_ids[i]]["name"]
if (i + 1 != collection_ids.length) {
return_string += "\n"
}
}
return return_string
}
collections_output()
@KalebNyquist
Copy link
Author

Using Zotero's Built-In CTRL-Key Option:

image

Using lookupZoteroCollections.js

image

@alialili
Copy link

Great, thank you!

@njss
Copy link

njss commented Mar 20, 2023

Really helpful! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment