DT3 Copiar referência da página do PDF em RTF

Esse script pressupões um campo de metadados bibkey para gerar a referência.


tell application id "DNtp"
        
    try
        
      set theRecord to the content record of think window 1
      if theRecord is {} then error "Select an item, please"
                
      set theBibkey to get custom meta data for "Bibkey" from theRecord default value ""
      set theURL to the reference URL of theRecord
                
      if the current page of think window 1-1 then
         set pageNumber to ((the current page of think window 1) as string)
         set thePage to "?page=" & pageNumber
            else
            set thePage to ""
      end if
                
         set pageURL to theURL & thePage
         set pageRef to display dialog "Qual número da página?" default answer ""
         set pageRef to text returned of pageRef
                
         set theHTML to ""
         set theHTML to theHTML & quoted form of ("<font face=\"gentium plus\"><a href=\"" & pageURL & "\">" & "(" & theBibkey & ", p." & pageRef & ")" & "</a></font></br>")
                
         set theRTFLink to (do shell script "echo " & theHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" as rich text)
                
        on error error_message number error_number
         if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
        end try
        
end tell