Created
July 3, 2014 13:24
-
-
Save dansheffler/77d53e6a4b281bb2f534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This gets | |
# (i) the file displayed in the front window | |
# (ii) the page number or index of the page displayed. The first page of a | |
# PDF is always 1. | |
# (iii) the page label of the page displayed. Thus the first pages can be | |
# labeled with roman numerals and later pages with arabic numberals. | |
tell application "Skim" | |
set skimFile to the file of the front document | |
set skimPage to the index of the current page of the front document | |
set skimLabel to the label of the current page of the front document | |
end tell | |
# This gets the citekey for the first reference in Bibdesk whose linked file | |
# is the PDF. | |
tell application "BibDesk" | |
set matchKeys to {} | |
repeat with currentPub in publications of front document | |
if linked file of currentPub is {} then | |
set bibFile to 0 | |
else | |
set bibFile to first item of linked file of currentPub | |
end if | |
if bibFile = skimFile then | |
copy cite key of currentPub to the end of matchKeys | |
end if | |
log bibFile | |
end repeat | |
# This puts the link onto the clipboard. | |
# E.g. [@mccabe94 [page 41](sk://mccabe94#57)] | |
get the clipboard | |
set the clipboard to "" | |
repeat with currentMatch in matchKeys | |
set myText to "[@" & currentMatch & " [page " & skimLabel & "](sk://" & currentMatch & "#" & (skimPage as text) & ")]" | |
set the clipboard to (the clipboard) & myText | |
end repeat | |
return the clipboard | |
end tell | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment