Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tell application "Bookends"
set theIDs to «event ToySRUID» "Selection"
repeat with theID in paragraphs of theIDs
tell front library window
try
set myRefs to (publication items whose id is theID)
set myItem to first item of myRefs
set thePath to path of attachment items of myItem
if thePath is not {} then
set {theKey, theAuthor, theEditor, theTitle} to {citekey, 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 "/aUsers/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
end if
on error errorMessage
end try
end tell
end repeat
end tell
@Dellu

This comment has been minimized.

Copy link

Dellu commented Mar 18, 2019

I am getting an error "Can't get item 1 of {}" when multiple items are selected.

@zverhope

This comment has been minimized.

Copy link
Owner Author

zverhope commented Mar 20, 2019

Yes, I hadn't tested this version on multiple selections as I mostly use the group version, but this should now work on multiple items (and now even knows to bypass those without attachments).

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.