DEVONthink and Papers

For those of you who use the RSS feature in DEVONthink Pro Office to track PubMed queries, here is a script that will export the reference from DTP to Papers and then match the reference. As always, If anyone can improve on this little script, please do so and share.


tell application id "DNtp"
    set theSelection to the selection
    set theList to "" --{}
    --set theCnt to 0 --added this section
    repeat with theRecord in theSelection
        set theText to plain text of theRecord
        if theText contains "PMID: " then
            set AppleScript's text item delimiters to "PMID: "
            set thePMID to (text item 2 of theText) as string
            if thePMID contains " [" then
                set AppleScript's text item delimiters to " ["
                set thePMID to (text item 1 of thePMID) as string
                tell application "Papers"
                    open location ("http://www.ncbi.nlm.nih.gov/pubmed/?term=") & thePMID
                    set m to selected mode of front library window
                    set selected mode of front library window to Reader Mode
                    set p to displayed publications of front library window
                    set aPub to first item of (selected publications of front library window as list)
                    set pmid of aPub to thePMID
                    delay 2.5
                    match (selected publications of front library window as list) without replacing metadata
                end tell
                set theList to theList & thePMID & return
                --set theCnt to theCnt + 1 -- added this section
            end if
        end if
    end repeat