Is it possible to automatically execute "Create bibliography for item" if given a key/citekey?

I'm working on an Alfred workflow (on MacOS) and would like to automatically generate the bibliographic entry for an item on demand.

Essentially, given a key for an item (BBT or zotero native key, captured earlier in the workflow), I want to have the bibliographic entry copied to the clipboard so I can paste it into a doc in a later stage of the workflow.

It isn't clear if this is strictly a client-side feature, or if I can perhaps make an API call to execute it.

I also have access to Keyboard Maestro if that is how it needs to be done.

Thanks!
  • You can make a format=bib API call with the item key.

    For local use, your main options would be to use BBT's debug-bridge and run some JavaScript or to use Alfred to open a zotero://select link to bring Zotero to the front with the item selected and initiate a Quick Copy.

    Using the web API would obviously prevent you from needing Zotero to be open.
  • edited March 22, 2021
    Thanks. Poking around with pyzotero a bit I don't see a way to quite do what I'm looking for. I'm already using python to query the auto-exported JSON that BBT keeps updated. Basically the simple script takes a cite key and returns the corresponding title. The `format` option returns XML/HTML/etc preformatted, I'm looking for just plain text.

    What I'm looking for next is a way to generate the actual text reference in APA or whatever format – the item that is pasted into the text or word doc. I'm only using BBT for the cite key feature right now, not using it in a LaTeX doc at all.

    The end to end feature I'm going for is, when the script is passed a cite key it creates a new file and pastes in the reference (APA or Chicago or whatever format) – that file is where I'll take notes on the source. I've got it doing everything I want except for getting the reference. I can get the reference manually via quick copy but don't see how to automate it yet.

    Is that something the debug bridge could support? If so where is documentation on it?

    Also where is the documentation on the x-callback-url scheme? I can't find it, only questions about how to have Zotero recognize callback URLs for other apps. If that is the route I need to go I can do it and run a Keyboard Maestro macro, or perhaps Alfred can do that also, I haven't experimented with sending keystrokes from it.

    Thanks.
  • edited March 22, 2021
    The `format` option returns XML/HTML/etc preformatted, I'm looking for just plain text.
    Citation styles are rich text. It doesn't make sense to ask for plain text from the API — the output would be incorrect for many styles. If you want to convert HTML to plain text and strip any rich-text formatting, spacing, indentation, etc., you can do so trivially after retrieving it. But format=bib is how you get bibliographic output from the API. (There are also include=citation and include=bib for getting bibliographic output separated by item.)
    Is that something the debug bridge could support?
    debug-bridge is just a way to run JavaScript in Zotero from outside. Anything Zotero can do can be done via JavaScript, so you can dig into the Zotero codebase if you want, but the web API is better documented.
    Also where is the documentation on the x-callback-url scheme?
    That's not something Zotero supports.
  • edited March 22, 2021
    > Citation styles are rich text. It doesn't make sense to ask for plain text from the API — the output would be incorrect for many styles.

    When I run the quick copy command in Zotero the content is pasted immediately into my plain text document without any conversion needed by me. This is why I assumed it was plain text. It's possible the app is making the conversion during paste though.

    > format=bib is how you get bibliographic output from the API

    Ah I see it now. Previously when experimenting with the API I was retrieving an HTML table which led me to think I would need to manually build the correct format for pasting into text.

    It appears `style` is the parameter I was looking for. I was looking in a separate section of the docs before.

    > That's not something Zotero supports.

    I meant the url scheme in general, I misspoke. I can't seem to find official documentation on the scheme, only various articles discussing it. Is there an official reference in the docs for the `zotero://` scheme?
  • When I run the quick copy command in Zotero the content is pasted immediately into my plain text document without any conversion needed by me.
    The citation processor does have a plain-text mode, which Zotero uses to pass plain text to the clipboard for pasting into plain-text fields. But that's a bit of a hack. If you take APA and strip italics and hanging indents, it's not really APA.

    In theory a flag to return text could be added to the API, but anything making an API request should be able to pretty easily convert HTML to plain text if that's really desired. The clipboard, by comparison, needs a plain-text variant for normal operation.
    Is there an official reference in the docs for the `zotero://` scheme?
    No, but you can see the zotero://select and zotero://open-pdf comments for the proper forms.
  • There's also BBTs pull-export. It currently only does per-collection or per-library pull, but per-item views would be trivial to do. If you don't yet have the citekey, BBTs CAYW should work.
Sign In or Register to comment.