Is there anyway I can open pdfs in Zotero pdf-viewer via the command line?

My workflow is:

- `Zotero`: name and manage citations
- `BetterBibtex`: to export bib file for use in `pandoc-markdown` based documents (`.md`, `.Rmd`).
- `Emacs`, `ebib`, and `pandoc-mode to write. I can jump to the BibTeX entry of a citation using `pandoc-mode`, which opens the BibTeX entry via `ebib`. `ebib` then allows me to open the associated PDF in an external PDF viewer.


Is there a way to open PDFs within the `Zotero` pdf-viewer via the command line without having to import the PDF into the `Zotero` database again?

Please let me know if you need more info about my question.

Thanks in advance.


Other relevant info:

ProductName: macOS
ProductVersion: 11.6.5
BuildVersion: 20G527
Zotero version: 6.0.10-beta.1+94372111f

  • edited July 6, 2022
    You can launch a zotero://open-pdf link with the open command. E.g.:

    open zotero://open-pdf/library/items/3TACGQKH

    But you'd have to know the item key at the end. @emilianoeheyns, the developer of Better BibTeX, would have to say whether there's anything BBT can do to help (e.g., pass the parent key through in the BibTeX entry in some unused field).
  • Thanks @dstillman. Is that the `uri` of the item? This does not seem to work for me... Whilst it brings `Zotero` to the frontmost application, it does not select the specified item nor does it open it.
  • I don't know what you mean by "`uri` of the item". The 8-character string at the end is what we call the item key.

    And I believe in the current version it will actually only work on the attachment item key, not the parent item key. We were going to expand it to function the same as double-clicking on the parent item, but I don't think we've merged that yet.

    You can get the key of a stored file by doing Show File and looking at the folder name, or you can select the attachment in the items list and run this from Tools → Run JavaScript:

    ZoteroPane.getSelectedItems()[0].key
  • Thanks for that.

    The `uri` I get from the `Zutilo` add-on `Copy-Zotero-URIs` context menu item. I selected the attachment and got the correct identifier, and it does work as you described.

    I wonder if @emilianoeheyns can provide more info on whether this is capable in `Better BibTeX`?
  • I already patch parseLibraryKey(/Hash), what I could do there is add a feature that if you request something like zotero://open-pdf/library/items/@citekey{ "attachment": "best" }, it would return the first result from getBestAttachments. I can't see whether I'm being called from open-pdf though, so all relevant information must be in the key portion of the URL.
  • zotero://open-pdf/library/items/@citekey
    OK, yeah, I was going to say we could potentially do this once we add built-in Citation Key support, but if you do already, that's good.
    { "attachment": "best" }
    Literally this? Why? You can just call getBestAttachment() automatically if the key is for a regular item. We'll be changing the built-in zotero://open-pdf to do that.
  • edited July 6, 2022
    What I meant to say above is that I cannot see what the URL is before the @, as that is not passed to parseLibraryKey(/Hash); only the ID is. I do not know whether the user is trying to open the item itself or its best attachment, or even whether parseLibraryKey(/Hash) is called for URL handling at all. The only patch point I could find into the URL handling was parseLibraryKey(/Hash), and I have no context there. So all context needs to be in the ID, unless parseLibraryKey(/Hash) would be passed the URL too.
  • Ah, I see what you mean — so you're patching that call for zotero://select too, in which case returning the attachment for a parent wouldn't be right? When I fix the parent-item thing I can see if we can give you anything better there.
  • if the key is for a regular item.
    Only regular items have keys, so this "if" is always true,
  • Ah, I see what you mean — so you're patching that call for zotero://select too
    Correct.
    When I fix the parent-item thing I can see if we can give you anything better there.
    I'll hold off on this then until that time. Thanks.
  • edited July 6, 2022
    Only regular items have keys
    ? That's not the case. All items, including child notes, attachments, and even annotations, have keys. The whole point here is that zotero://open-pdf only works on attachment-item keys at the moment, not regular-item keys.
  • Sorry -- only regular items have citekeys
  • Ah, right, OK.
Sign In or Register to comment.