Get Zotero item key from Firefox

To read an item via the Zotero API, you need to have the item key. Oddly, the Zotero Firefox app does not provide simple access to the item keys. The following export translator will copy the item keys as a comma-separated list to the clipboard on Ctrl+Shift+c in the usual manner. The translator needs to be saved as a javascript file (.js file extension) in the Zotero translators directory. My translators directory was here ~/.mozilla/firefox/wgcm6dkk.default/zotero/translators/. The code is based on that found here: https://gist.github.com/nschneid/3134386, but pared down to give nothing apart from the list of item keys.

{
"translatorID":"0dbe4ec8-597c-4cc7-bfb5-c38321c5c689",
"translatorType":2,
"label":"Zotero Item Key",
"creator":"Adam Smith",
"target":"html",
"minVersion":"2.0",
"maxVersion":"",
"priority":200,
"inRepository":false,
"displayOptions":{"exportCharset":"UTF-8"},
"lastUpdated":"Fri 22 Aug 2014 12:24:20 PM EDT"
}

function doExport() {
   var item;
   if(item = Zotero.nextItem())
   {
      Zotero.write(item.key);
   }
   while(item = Zotero.nextItem())
   {
      Zotero.write(','+item.key);
   }
}

Leave a Reply

Your email address will not be published. Required fields are marked *