Skip to content

Instantly share code, notes, and snippets.

@dansheffler
Created July 3, 2014 13:36
Show Gist options
  • Save dansheffler/3f1f74ccc883186c0b75 to your computer and use it in GitHub Desktop.
Save dansheffler/3f1f74ccc883186c0b75 to your computer and use it in GitHub Desktop.
# 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.
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
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 URL onto the clipboard.
# E.g. sk://mccabe94#57)
get the clipboard
set the clipboard to ""
repeat with currentMatch in matchKeys
set myText to "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