* Select the reference.
* Open the PDF.
* Select the DOI text field on the PDF. The text field must have one of these two "delimiters" - doi.org/ or DOI:
* Run the script.
The script will capture the DOI to the clipboard, paste it back to the reference, and run an AutoFill from Internet command.
CAVEATS - The script requires that you cannot have the reference in the left pane as an active selection. The reference must be highlighted gray not blue. Otherwise, the script captures the wrong information to the clipboard. I would appreciate any insights on how to "deselect" the left pane and reselect it after capturing to the clipboard.
Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
(**
this parses the DOI on a PDF, fills the DOI into the reference, and runs AutoFill
version 2023-10-15
author jjw
**)
on run
tell application "Bookends"
activate
set theWindowList to the name of every library window as list
tell application "System Events" to keystroke "c" using command down
set theText to (the clipboard as text)
set theReference to the selected publication items of the front library window
set theDOI to the get_DOI(theText) of me as text
set the doi of item 1 of theReference to theDOI
tell application "System Events" to keystroke "a" using {shift down, command down}
end tell
end run
on get_DOI(DOItext)
set theCD to AppleScript's text item delimiters as text
set AppleScript's text item delimiters to "doi.org/"
set theItemList to every text item of DOItext as list
try
set theReturn to text items 2 thru end of theItemList as text
on error
set AppleScript's text item delimiters to "doi:"
set theItemList to every text item of DOItext as list
set theReturn to text items 2 thru end of theItemList as text
end try
set AppleScript's text item delimiters to theCD
return theReturn
end get_DOI