# Hook and Zotero

**URL:** https://discourse.hookproductivity.com/t/hook-and-zotero/4618
**Category:** Discussion & Help
**Created:** [February 3, 2022, 11:03am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618 "2022-02-03T11:03:32Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 11:03am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/1 "2022-02-03T11:03:33Z")

</div>

Zotero 5.0.96.3  
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](https://discourse.hookproductivity.com/t/example-of-making-zotero-work-with-hook/1698)).

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 http://127.0.0.1:23119/zotxt/items`

which throws an error but by experimenting found that removing the ‘&format=json’  
` curl -s -d selected=t --get [http://127.0.0.1:23119/zotxt/items](http://127.0.0.1:23119/zotxt/items)

which produces

```auto
[
  {"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

```auto

[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.

---

<div class="post-metadata">

### Author: ![brock](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/brock/32/435_2.png) [@brock](https://discourse.hookproductivity.com/u/brock)
#### Post date: [February 3, 2022, 11:38am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/2 "2022-02-03T11:38:43Z")

</div>

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 [http://127.0.0.1:23119/zotxt/items](http://127.0.0.1:23119/zotxt/items)

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](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?

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 11:50am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/3 "2022-02-03T11:50:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 11:55am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/4 "2022-02-03T11:55:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 12:17pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/5 "2022-02-03T12:17:22Z")

</div>

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

» curl -s -d selected=t\&format=json -G [http://127.0.0.1:23119/zotxt/items](http://127.0.0.1:23119/zotxt/items)

```auto
[
  {"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"}
]

```

---

<div class="post-metadata">

### Author: ![brock](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/brock/32/435_2.png) [@brock](https://discourse.hookproductivity.com/u/brock)
#### Post date: [February 3, 2022, 12:30pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/6 "2022-02-03T12:30:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 12:52pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/7 "2022-02-03T12:52:28Z")

</div>

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"`

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 1:02pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/8 "2022-02-03T13:02:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 1:43pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/9 "2022-02-03T13:43:44Z")

</div>

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

`zotero://select/library/items/ASFV3ECW`

If instead I select the BibTex citation key I get

`zotero://select/items/@noauthor_iso%2Fiec%2Fieee_2011`

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.

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 3, 2022, 2:04pm UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/10 "2022-02-03T14:04:06Z")

</div>

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](https://stackoverflow.com/questions/23852182/i-need-to-url-encode-a-string-in-applescript)
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.

---

<div class="post-metadata">

### Author: ![curl](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@curl](https://discourse.hookproductivity.com/u/curl)
#### Post date: [February 4, 2022, 9:11am UTC](https://discourse.hookproductivity.com/t/hook-and-zotero/4618/11 "2022-02-04T09:11:04Z")

</div>

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:

```auto
curl -s -d selected=t\&format=key -G http://127.0.0.1:23119/zotxt/items
[
  "1_ASFV3ECW"
]%

```

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