forked from davepwsmith/zotpick-applescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zotpick-mmd.applescript
38 lines (38 loc) · 1.34 KB
/
zotpick-mmd.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
tell application "System Events"
try
set appName to (the name of every process whose frontmost is true) as string
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://localhost:23119/better-bibtex/cayw?probe=probe' 2>/dev/null; exit 0"
if zotRunning is "" then
display alert "Zotero not running" message "This script will not work unless Zotero is running. Please launch Zotero and try again"
tell application appName
activate
end tell
error number -128
else if zotRunning is "No endpoint found" then
display alert "Better BibTeX not installed" message "This script will not work unless Better BibTeX is installed. Please make sure that Better BibTeX is installed in the running instance of Zotero"
tell application appName
activate
end tell
error number -128
else if zotRunning is "ready" then
set theReference to do shell script "/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=mmd' 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
keystroke theReference
on error errMsg
display alert errMsg
end try
end tell
end if