Better Zotero file management with Zotfile

In this post I'm detailing my Zotero setup. It took me a while to figure out all the bits and pieces and I figure describing my configuration might be helpful to someone else.

Why isn't the default Zotero setup good enough?

The main issue is the way files that are attached to Zotero entries get stored. In the default setup, Zotero saves the PDF (and other) documents in the Firefox profile directory. The path to your library (on Linux) looks like this:

~/.mozilla/firefox/Profiles/<randomstring>/zotero

I find this very impractical. But it gets worse: Even knowing this path, it is impossible to predict where a specific file will be stored, as Zotero creates random(?) subdirectories in which the files are stored, using equally cryptic file names. This makes locating Zotero attachements in the file system unnecessarily hard.

Zotfile to the rescue!

Zotfile, written by Joscha Legewie, is a plug-in for Zotero that is able to address almost every issue I have with Zotero. Download it from the plugin's website and consider supporting the developer if you find the tool as useful as I do.

Renaming & Relocating with Zotfile

Renaming and relocating the attachments is easy using Zotfile. Open the Zotfile preferences in Zotero (located right under the standard preferences) and define your location and renaming rules. Combing the default wildcards you can get pretty nice results already.

For example, the rule %a%y renames attachments in the format Authorname2002.

Document type specific renaming rules with custom wildcards

However, if you would like document type specific renaming and relocating rules you have to resort to writing your own wildcards. Here's two things I wanted to do:

  • For specific document types (manuscripts) I want to adapt the default AuthorYear renaming rule to include the title as well, AuthorYear_Title.
  • For relocating, I would like custom folder names for the different documents types. For example, instead of sorting journal article type documents into Journal Articles/, I'd rather have them in a folder articles/.

This can be achieved by the following two wildcards %3 and %4. The renaming rules I have defined as

{
   "3": {
      "default": {},
      "manuscript": {
         "field": "title",
         "operations": [
            {
               "function": "replace",
               "regex": " ",
               "replacement": "-"
            },
            {
               "function": "replace",
               "regex": "^(.*)$",
               "replacement": "_$1"
            }
         ]
      },
      "book": {
         "field": "title",
         "operations": [
            {
               "function": "replace",
               "regex": " ",
               "replacement": "-"
            },
            {
               "function": "replace",
               "regex": "^(.*)$",
               "replacement": "_$1"
            },
            {
               "function": "replace",
               "regex": "^(.{200}).*$",
               "replacement": "$1"
            }

         ]
      },
      "conferencePaper": {
         "field": "title",
         "operations": [
            {
               "function": "replace",
               "regex": " ",
               "replacement": "-"
            },
            {
               "function": "replace",
               "regex": "^(.*)$",
               "replacement": "_$1"
            }
         ]
      },
      "report": {
         "field": "title",
         "operations": [
            {
               "function": "replace",
               "regex": " ",
               "replacement": "_"
            },
            {
               "function": "toLowerCase"
            }
         ]
      }
   },
   "4": {
      "default": {
         "field": "itemType",
         "operations": [
            {
               "function": "replace",
               "regex": "Journal Article",
               "replacement": "articles"
            },
            {
               "function": "replace",
               "regex": "^Book$",
               "replacement": "books"
            },
            {
               "function": "replace",
               "regex": "Manuscript",
               "replacement": "manuscripts"
            },
            {
               "function": "replace",
               "regex": "^Book Section$",
               "replacement": "book_sections"
            },
            {
               "function": "replace",
               "regex": "Document",
               "replacement": "documents"
            },
            {
               "function": "replace",
               "regex": "Thesis",
               "replacement": "thesis"
            },
            {
               "function": "replace",
               "regex": "Presentation",
               "replacement": "presentations"
            },
             {
               "function": "replace",
               "regex": "Conference Paper",
               "replacement": "conferences"
            }
         ]
      },
      "report": {
         "field": "extra"
      }
   },
   "5": {
      "default": {
         "field": "extra",
         "operations": [
            {
               "function": "replace",
               "regex": "^(?!poster).*$",
               "replacement": ""
            },
            {
               "function": "replace",
               "regex": "poster=(.*)",
               "replacement": "_$1"
            }
         ]
      }
   }
}

Here, %3 is for the renaming while %4 handles the relocating. My renaming rules are

and the relocating rules are

Since Zotero allows neither manual nor conference poster item types, I have custom solutions to create specific behavior for such documents. I give manuals the item type report while specifying the "extra" field as, for example, manuals/latex. Using %4, these documents get filed to exactly that location.

For posters, I select the item type journalArticle and set the field "extra" as poster=CONFERENCE_NAME. With this, posters get renamed as Hoffmann_BCCN2016, for example.

If you want to define wildcards yourself, or want to use the one above, you should first validate the JSON (I used pro.jsonlint.com) and then convert it to a single line of code (I used freemformatter.com).

Syncing across multiple machines

Setting up Zotero in this way allows you to easily synchronize your Zotero library across multiple machines. All you need to do is:

  1. Synchronize your library directory (the one you specified in Zotfile), for example via Dropbox or ownCloud.
  2. Synchronize your Zotero profile via the service provided within Zotero (you have to create an account).
  3. IMPORTANT: In the Zotero(!) settings find the option Advanced - Files and Folders and set the path of the Linked Attachment Base Directory to your library directory (same as in 1.).

Easily sharing papers

Another helpful feature that Zotfile provides is exporting the pdfs attached to a collection or selection within Zotero. This is specifically convenient when you need to share papers with your colleagues via Email, Dropbox or even USB stick.

To do this, set up the Send to Tablet functionality. You don't need to actually send it to a tablet. All it really does is copy selected pdfs to a folder you specified. From there you can easily copy the files to wherever you want to have them.