tell application "Zotero" to activate
tell application "System Events"
tell process "Zotero"
repeat 2 times
keystroke "c" using {command down, shift down} --copyselectitemlink快速复制快键commad+shift+C
delay 1 --0.5s即可复制完毕
end repeat
end tell
end tell
set myStr to do shell script "pbpaste"
set AppleScript's text item delimiters to "
" --设置分隔符此分隔符纯文本复制报错需从程序中拷贝
set myList to text items in myStr
set zoterocode to ""
set codes to ""
repeat with j from 1 to the length of myList
set itemValue to item j of myList
--set zoteroitem to (do shell script "sed -E 's#zotero://select/library/items/##g' <<< " & itemValue)
set zoteroitem to (do shell script "sed -E 's#zotero://select/items/0_##g' <<< " & itemValue)
set zoterocode to "{\"uris\":[\"http://zotero.org/users/6410589/items/" & zoteroitem & "\"]}" --引号前加\转义
if j = 1 then
set codes to zoterocode
set fieldcode to "[1] ZOTERO_ITEM CSL_CITATION {\"citationItems\":[" & codes & "]}"
else
set codes to codes & "," & zoterocode
set fieldcode to "[1-" & j & "] " & "ZOTERO_ITEM CSL_CITATION {\"citationItems\":[" & codes & "]}"
end if
end repeat
tell application "Microsoft Word"
activate
--书目1及以上改为bibliography,防止插入时缩进变化
set filename to full name of active document
if not (exists (Word style "Bibliography" of active document)) then
repeat with k from 5 to 1 by -1
set nowstyle to "书目" & k
if exists (Word style nowstyle of active document) then
set name local of Word style nowstyle of active document to "Bibliography"
if k ≠ 1 then
repeat with l from k - 1 to 1 by -1
set nowstyle to "书目" & l
organizer delete source filename name nowstyle organizer object type organizer object styles
end repeat
end if
end if
end repeat
end if
tell selection
create new field text range text object field type (field author) field text (fieldcode) preserve formatting (true)
run VB macro macro name "ZoteroRefresh" --更新zotero太慢,等删除完成还未更新
end tell
end tell
'
插入文献,设置Word样式库中的“Bibliography”格式(例如缩进等),点击zotero插件栏的“Refresh”,一切正常;一种办法是:把Word转换成英文版就可以了(因为英文版不会将”Bibliography“转变为”条目1“),但英文版对于字体集等的显示又不友好。 还有一种办法,在使用本插件插入前,将最新的“书目3”改为“Bibliography”,删除其他的“书目2”、“书目1”,就可以保留之前设置好的样式。这个方法可以用aplescript实现,但不知是否可以优化使用本插件实现?
以下是我使用的applescript,可以作个参考:
需要解压并复制此文件Zotero Select Item.js.zip在zotero的目录
/Users/username/Zotero/translators/Zotero Select Item.js