-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathzotpick-pandoc for Scrivener.applescript
49 lines (46 loc) · 1.61 KB
/
zotpick-pandoc for Scrivener.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# App to keystroke citations from Zotero into Scrivener
# Set a delay between keystrokes for OS Sienna bug
set keyDelay to 0.01
tell application "System Events"
try
-- Have to hardcode Scrivener here because it seems to make the script the frontmost app
set appName to "Scrivener"
on error errMsg
display alert "Problem" message "Could not get the name of the frontmost application."
error number -128
end try
end tell
set zotRunning to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?probe=probe' 2>/dev/null; exit 0"
if zotRunning is "ready" then
set theReference to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?format=pandoc' 2>/dev/null; exit 0"
try
repeat until application appName is frontmost
tell application appName to activate
end repeat
on error errMsg
display alert errMsg
end try
tell application "System Events"
try
repeat with letter in theReference
keystroke letter
delay keyDelay
end repeat
on error errMsg
display alert errMsg
end try
end tell
else
if zotRunning is "" then
set alertTitle to "Zotero not running"
set alertMessage to "This script will not work unless Zotero is running. Please launch Zotero and try again."
else if zotRunning is "No endpoint found" then
set alertTitle to "Better BibTeX not installed"
set alertMessage to "This script will not work unless Better BibTeX is installed. Please make sure that Better BibTeX is installed in the running instance of Zotero."
end if
display alert alertTitle message alertMessage
tell application appName
activate
end tell
error number -128
end if