Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daaaaaaaaaniel/c5cbddd32fc4f4243e8a5f05663f7dc8 to your computer and use it in GitHub Desktop.
Save daaaaaaaaaniel/c5cbddd32fc4f4243e8a5f05663f7dc8 to your computer and use it in GitHub Desktop.
tell application "Bookends"
tell front library window
set theIDs to get id of publication items of group item "Unlinked Attachments"
repeat with theID in theIDs
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set {theKey, thePath, theAuthor, theEditor, theTitle} to {citekey, path of attachment items, authors, editors, title} of myItem
if theAuthor = "" then set theAuthor to theEditor
set theRIS to format myItem using "RIS.fmt"
set otid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set thePath to text items of thePath
repeat with i in thePath
set thisPath to i as string
tell application "Finder" to set theName to name of (POSIX file thisPath as alias)
set AppleScript's text item delimiters to otid
try
if (characters -4 thru -1 of theName as string) is ".pdf" then do shell script "/usr/local/bin/exiftool -title=" & quoted form of theTitle & " -author=" & quoted form of theAuthor & " -subject=" & theKey & " -overwrite_original " & quoted form of thisPath
end try
tell application id "DNtp"
set theDatabase to open database "/Users/zhope/DTPO/Research.dtBase2"
set theLocation to create location "/Library"
set theRecord to indicate thisPath to theLocation
set URL of theRecord to ("bookends://sonnysoftware.com/" & theID) as text
set aliases of theRecord to theKey
set comment of theRecord to theRIS
set theLink to reference URL of theRecord
end tell
end repeat
set user20 of myItem to theLink
on error errorMessage
end try
end repeat
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment