2011/03/25

How to create correctly the Skim notes which have the DEVONthink links, when you have already annotated the first page of the PDF document

In my post "How to put DevonThink links in Skim notes" I described how you can create to a PDF file a number of Skim notes with various versions of references to itself. These notes are created in the first page of the document and an example of them is shown below:



In my post "Automated creation of a LaTeX compatible citation only from Skim! (with hyperlink included)" I write that "it is required that you create these notes when there are no annotations in the first page of the PDF file. Otherwise these four notes will take another index number and you will need to adjust accordingly the AppleScript".

Now it is time to overcome this limitation!

Specifically, I wrote an AppleScript which temporarily removes all your annotations from your PDF file, then creates the desirable notes with the correct index numbers and at the end reinserts your annotations. You should run this script when you have selected one or more PDF files from a DEVONthink database.

The AppleScript code is the following:
--2011-03-25
--http://organognosi.blogspot.com

tell application id "com.devon-technologies.thinkpro2"
    set these_items to the selection
    if these_items is {} then error "Please select some contents."
   
    repeat with this_item in these_items
       
        set RecordLink to the reference URL of this_item
        set DevonThinkLink to RecordLink & "?page=0"
        set PdfPath to get the path of this_item
        set PdfName to the name of this_item
       
        tell application "Skim"
            open PdfPath
            set docPath to path of front document
            set notesPath to text 1 thru -5 of docPath & " (notes).skim"
           
            save front document
            save front document in notesPath as "Skim notes"
           
            delete notes of front document
           
            tell page 1 of document 1
                make note with properties {type:anchored note, bounds:{523, 820, 540, 820}, text:"(<rawtex></rawtex>: [" & RecordLink & "?page=])", extended text:DevonThinkLink}
                delay 0.1
                make note with properties {type:anchored note, bounds:{523, 800, 540, 800}, text:"(: \\href{" & RecordLink & "?page=}{})"}
                delay 0.1
                make note with properties {type:anchored note, bounds:{523, 780, 540, 780}, text:"([[" & PdfName & "]]: [" & RecordLink & "?page=])"}
                delay 0.1
                make note with properties {type:anchored note, bounds:{523, 760, 540, 760}, text:DevonThinkLink, extended text:PdfName}
                delay 0.1
                make note with properties {type:anchored note, bounds:{523, 760, 540, 760}, text:"0"}
            end tell
            read notes front document from notesPath without replacing
        end tell
    end repeat
end tell

2011-04-02
Moreover, this AppleScript creates a fifth Skim note in the first PDF page with the default value zero. For more information about this note see my post "Latin page numbers, Arabic page numbers and the fifth Skim note".

1 comment:

Jy Yun said...

I appreciate your sharing. I was doing this kind of thing manually. Then somepoint I quit becuase it was tiresome. Now I can do it just one click with your script. Thank you so much.