Last active
November 12, 2022 05:41
-
-
Save zverhope/9e9e55f5738cd3674a89f701622fbf12 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
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 |
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
I am getting an error "Can't get item 1 of {}" when multiple items are selected.