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.