Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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
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://" & 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

This comment has been minimized.

Copy link

@Dellu Dellu commented May 3, 2019

Thank you. This is very useful script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.