Hook and Zotero

zotxt 5.1.4
Hook 3.4.1

I’ve installed zotxt and was hoping to be able to link to a Zotero library item (following this discussion).

The problem I’m getting is the ‘no linkable items’ message.

I’ve checked zotxt. Initially using
curl -s -d selected=t&format=json -G

which throws an error but by experimenting found that removing the ‘&format=json’
` curl -s -d selected=t --get

which produces

  {"id":"noauthor_iso/iec/ieee_2011","citation-key":"noauthor_iso/iec/ieee_2011","issued":{"date-parts":[[2011]]},"publisher":"International Standards Organisation","title":"ISO/IEC/IEEE 42010: 2011: Systems and Software Engineering, Architecture Description","type":"report","URL":"https://www.iso.org/standard/50508.html"}

returns the selected reference item in what looks like a JSON format.

Next I checked the AppleScript in Hook under Zotero > Get Address

The AppleScript throws an error. At the end of the script the line

set theLink to item 2 of theTextItems

causes an error because there is only 1 item - the citation key. Changing this from ‘2’ to ‘1’ produces a result for theLink

[ISO/IEC/IEEE 42010: 2011: Systems and Software Engineering, Architecture Description](zotero://select/library/items/noauthor_iso/iec/ieee_2011)

which looks like the correct markdown link.

… but I still have no linkable items as far as Hook is concerned.

On pasting the Markdown link and clicking on it I get Zotero opening but it selects all of the references and all of the enclosed snapshots, notes et al i.e. the focus of the selection is not the specified reference but the entire collection so for some reason the URL scheme zotero://select/library/items/id isn’t working either.

I guess the first problem is to get a working zotero:// link but I’d like to understand how then to get rid of the ‘no linkable items’ error.

For this command to work at a terminal window, you need to escape the ‘&’ character, e.g. ‘&’

curl -s -d selected=t&format=json -G

I have the same version of everything. When I run this at the terminal, I get a JSON output with an ID of the form:

“id”: "http://zotero.org/users/6738152/items/3WIH9AJY

I can do this for either the top-level reference or an enclosed PDF and I get a result in the same format but with a different final part to the string.

The markdown produced is:

Ecarnot et al. - 2015 - Writing a scientific article A step-by-step guide.pdf

This all works as expected.

I think that what we need to discover is why Zotero is giving differently structured ID fields for you. Do you have multiple libraries?

I’ve just been experimenting with Zotero. If I select the reference and CMD + Shift + C and paste into a text editor I get

{ | anon. ISO/IEC/IEEE 42010: 2011: Systems and Software Engineering, Architecture Description, 2011 | | |zu:4023562:ASFV3ECW}

it seems that the ‘ASFV3ECW’ is the missing key to making the zotero:// link work.

I have a single library.

Could this be the Better BibTex citation key format setting under Preferences? e.g. [zotero:clean]

With the escaped ‘&format=json’ the curl output is exactly the same as without i.e.

» curl -s -d selected=t\&format=json -G

  {"id":"noauthor_iso/iec/ieee_2011","citation-key":"noauthor_iso/iec/ieee_2011","issued":{"date-parts":[[2011]]},"publisher":"International Standards Organisation","title":"ISO/IEC/IEEE 42010: 2011: Systems and Software Engineering, Architecture Description","type":"report","URL":"https://www.iso.org/standard/50508.html"}

Could well be a preference setting. I don’t have Better BibTex installed and if I do cmd-shift-c I just get a neatly formatted bibliography entry when I paste.

The format for CMD + Shift + C is set under Preferences > Export > Quick Copy
e.g. ‘For Markdown’ produces
[*ISO/IEC/IEEE 42010: 2011: Systems and Software Engineering, Architecture Description*]: <https://www.iso.org/standard/50508.html> "(2011). International Standards Organisation.https://www.iso.org/standard/50508.html"

The earlier one I included appears to be ‘Scannable Cite’.

Still none the wiser wrt the format of the Citation Key field which seems to be the problem.

Interestingly Better BibTex has it’s own Export > Quick Copy preference setting which can be set to ‘Zotero select link’ and ‘using Zotero item key’ which can then be referred to from the main Zotero Preferences (Export) selecting default format ‘Better BibTex Quick Copy: Zotero select link’ which produces the URL


If instead I select the BibTex citation key I get


which looks like the Citation Key I’m seeing in the main Zotero window information pane.

The second form of Zotero url appears to work so all that needs to be done in the AppleScript is to url-encode ’ noauthor_iso/iec/ieee_2011’ to give me a workable URL.

Finally working.

In summary:-

  1. Citation keys of form [author][short_title][date]
  2. Citation key has to be url-encoded
  3. Expected url is then zotero://select/items/@citation_key

Modified AppleScript for Zotero:-

  1. choose first, not second item - set theLink to item 1 of theTextItems
  2. url encode the key - set theLink to urlencode(theLink) see urlencode - I need to URL-encode a string in AppleScript - Stack Overflow
  3. prefix with an ‘@’ - set theLink to "[" & theName & "](zotero://select/items/@" & theLink & ")"

and I now have selectable links in Zotero as far as Hook is concerned.

1 Like

Interestingly a bit of experimentation with the zotxt API shows that if I use format=key (instead of format=json) I get something that is much closer to the key format in a single step:

curl -s -d selected=t\&format=key  -G

which would only require the 1_ to be stripped off to form the URL.

1 Like