Hoping for some assistance please.
Can the zotero script be modified to: First Author Surname Year and Title?
The current default is Title alone.
I suspect it will be a change to this line in the script:
set theLink to “[” & theName & “](zotero://select/items/” & theLink & “)”
Thanks
Sorry this fall through the cracks.
Here is a customized script you can try on your machine.
Please copy the following script and paste in Hook->Preference window ->Scripts->Zotero->Get Address, click save button. You can always go back to the default script by clicking “Reset to default” button.
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 authors to author of item 1 of aList
set firstSurname to ""
if authors is not {} then
set firstSurname to family of item 1 of authors
end if
set issuedYear to ""
set issuedYears to issued of item 1 of aList
if issuedYears is not {} then
set issuedYears to |date-parts| of issuedYears
if issuedYears is not {} then
set issuedYears to item 1 of issuedYears
end if
if issuedYears is not {} then
set issuedYear to item 1 of issuedYears
end if
end if
set zotext_result to do shell script "curl -s -d selected=t\\&format=key -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 theLink to item 1 of aList
set theLink to "[" & firstSurname & "-" & issuedYear & " " & theName & "](zotero://select/items/" & theLink & ")"
return theLink
The previous code will not work if author or year does not exist. Here is the updated code:
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 firstSurname to ""
set issuedYear to 0
try
set authors to author of item 1 of aList
if authors is not {} then
set firstSurname to family of item 1 of authors
end if
end try
try
set issuedYears to issued of item 1 of aList
if issuedYears is not {} then
set issuedYears to |date-parts| of issuedYears
if issuedYears is not {} then
set issuedYears to item 1 of issuedYears
end if
if issuedYears is not {} then
set issuedYear to item 1 of issuedYears
end if
end if
end try
set zotext_result to do shell script "curl -s -d selected=t\\&format=key -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 theLink to item 1 of aList
set nameYear to ""
if length of firstSurname is not 0 and issuedYear is not 0 then
set nameYear to firstSurname & "-" & issuedYear & "-"
else if length of firstSurname is not 0 then
set nameYear to firstSurname & "-"
else if issuedYear is not 0 then
set nameYear to issuedYear & "-"
end if
set theLink to "[" & nameYear & theName & "](zotero://select/items/" & theLink & ")"
return theLink