Example of making Zotero work with Hook

I appear to have Zotero working with Hook, with the caveat that you need to install the ‘zotxt’ plugin for Zotero. The GetAddress script queries the inbuilt webserver of Zotero via the API that zotxt exposes twice to get the key of the selected item and then the title of the selected item, and then forms a markdown link for them.

It works for me, but I was hoping that someone who actually knows AppleScript could provide comments (especially the kludge to get the title field from the response). Also it would be useful for other Zotero users to test.

set zotext_result to do shell script "curl -s -d selected=t\\&format=key  -G"
set AppleScript's text item delimiters to quote
set theTextItems to every text item of zotext_result
set link to "zotero://select/items/" & item 2 of theTextItems
set zotext_result to do shell script "curl -s -d selected=t\\&format=json  -G"
set AppleScript's text item delimiters to "\"title\""
set newText to text items of zotext_result
set AppleScript's text item delimiters to "\""
set newText2 to text items of item 2 of newText
set theName to item 2 of newText2
set theLink to "[" & theName & "](" & link & ")"
return theLink
1 Like
  1. Awesome! The script worked for me in connecting Zotero and Obsidian.
  2. I wish I could help with the scripting. Sorry.
1 Like

Thanks for that, @brock ! And Welcome to the Hook Productivity Forum , @harets ! Great to see integration with Zotero. I used it a long time ago before switching to Papers. But Papers2020 lacks automation, so I personally am switching to Bookends. Hook working with zotero is very helpful to many. We will look at the AppleScript in more detail. On Linkable Mac Apps – Hook, I’ve added a link to this topic .

Thanks again, @brock.

We’ve made some changes to the proposed Zotero script. We’d love to get some feedback from you or another Zotero user regarding the changes. To quote our dev who did the work:

  1. Convert JSON string to JSON object using AppleScriptObj-C, so we can correctly retrieve the title value. If We use delimiter quote to break text apart to get title value, it will have problem if title itself contains a quote.

  2. Get item ID and item title from the same entity of JSON response. This will make sure the ID and title are from the same item when there are multiple selections, though it rarely happens.

  3. Change URL zotero://select/items/id to zotero://select/library/items/id. For URL zotero://select/items/id, opening it only opens Zotero window, it does not select the right entry. URLs of the form zotero://select/library/items/id seem to work fine. That’s what happens on my Mac. I would like to see the user’s feedback. They are more familiar with Zotero.

Here’s her revision:

use scripting additions
use framework "Foundation"

set zotext_result to do shell script "curl -s -d selected=t\\&format=json  -G"
set str to current application's NSString's stringWithString:zotext_result
set theData to str's dataUsingEncoding:(current application's NSUTF8StringEncoding)

set {res, theErr} to current application's NSJSONSerialization's JSONObjectWithData:theData options:0 |error|:(reference)
if res is missing value then error (theErr's localizedDescription() as text) number -10000
set aList to res as list

set theName to |title| of item 1 of aList

set theId to |id| of item 1 of aList
set AppleScript's text item delimiters to "/items/"
set theTextItems to every text item of theId
set theLink to item 2 of theTextItems

set theLink to "[" & theName & "](zotero://select/library/items/" & theLink & ")"

return theLink

Thank you!

( 2020-07-23 @ 09:17 I fixed two typos in the description, not the script. Discourse forum software can do a ‘diff’.)

Seems to work OK for me too, presuming that pasting the updated script into the window in Hook is sufficient to update what Hook is actually running. Clicking a pasted link selects the correct item and opens Zotero first if it isn’t running.

I now need to sit and look at the changes in detail so I learn some more AppleScript - my version was just pasted from various scripts and hacked at until it worked :slight_smile:

1 Like

Thanks @brock. We have published Hook integration scripts v. 124 — with support for Zotero, also updates Daylite.

Hi @LucB, I have just updated Hook Using Hook’s Check for App Updates and Update Scripts function and when I trigger Hook it says there is no linkable item in Zotero.

Do I need to add the above script too?

Thank you!

The zotero scripts built into the app are the ones we’ve provided. Please make sure they are not overridden ( a * would show up if they were). It’s early days for Zotero integration – not having received much feedback about it.

I had this issue yesterday, but noticed that it was because I had an attached PDF selected in Zotero rather than the reference that the attachment was attached to. When I selected the reference, Hook worked as expected.

1 Like

Thank you to you both.

I checked and the scripts are not overridden - there was no a *, just the Hook logo with the text ‘no linkable item in Zotero’ below.

I tried linking to references in Zotero with or without a pdf and was told ‘no linkable item in Zotero’. I also tried linking to a pdf in Zotero, rather than the actual reference, and that did not work either.

Hi Aaron, Have you given accessibility permission for Hook to interact with Zotero?
Accessibility Permissions – Hook

Hi LucB, I have grant accessibility permission to Hook but I don’t get the options you do within Hook. In fact, I don’t have the ‘automation’ menu. Please see below.Security___Privacy

what version of macOS are you using, @Aaron?

also, are you using an account with admin privileges or just a regular user account?

Yesterday, I was working on my work computer. Not sure what version of macOS is on that machine. I will check next week. But the same issue is occurring on my home Mac, which is using macOS High Sierra (10.13.6).

I have a regular account on my home Mac. Not sure about the work computer. I don’t normally hit any permission access issues.

If it helps, I am also getting the ‘no linkable item’ now in Microsoft Word and Microsoft OneNote. Not sure if these apps are supported or not.

Microsoft 2016+ office are supported

Both Word and OneNote are the latest versions so what could be causing the ‘no linkable item’ issue for Word, OneNote and Zotero? When I go to ‘About’ in Hook I can see that my Essentials licence is recorded so its not a licence issue.

Does anything in the No Linkable Item in … page apply?

Hi @LucB, no, nothing in that link applies.

I wonder whether I am using Hook correctly? I can link to a Word document in Finder but when the same document is open (and Word is the top screen and no other palette is open) Hook says there is ‘no linkable item’. Is this right?

I save all my files locally but they are synced with OneDrive. Could this be causing the issue? I have made sure that any Word doc has finished saving when attempting to Hook with it.