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:
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.
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.
Change URL
zotero://select/items/id
tozotero://select/library/items/id
. For URLzotero://select/items/id
, opening it only opens Zotero window, it does not select the right entry. URLs of the formzotero://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 http://127.0.0.1:23119/zotxt/items"
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’.)