2011/04/05

Automated creation of references with hyperlinks from Skim


In the post "Automated creation of a LaTeX compatible citation only from Skim! (with hyperlink included)" there is an AppleScript which creates a LaTeX reference in TextMate for the PDF file that you currently read in Skim. Now I will present an expanded and improved version of that AppleScript. Specifically the new AppleScript takes advantage of all my standardized notes in the first page of a PDF document.

These notes can be created automatically from the AppleScript in the post "How to create correctly the Skim notes which have the DEVONthink links, when you have already annotated the first page of the PDF document". Moreover you can find more information about these notes in my posts "How to put DevonThink links in Skim notes" and "Latin page numbers, Arabic page numbers and the fifth Skim note".

The references and hyperlinks that can be created from my new AppleScript are the following and correspond to the notes one through four:

1. A LaTeX reference to the exact PDF page which can be inserted in a MediaWiki page without any modifications or problems. Moreover, the necessary code for the creation of MediaWiki link is also included. An example is the following:
 (<rawtex>\cite{Deconstructing-the-Laws-of-Logic-Clark-2008a}</rawtex>: [x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=2 27])
A prerequisite for the use of this reference is to have installed and properly customized the Wiki2LaTeX MediaWiki extension. I will write more about this and its importance in a future post.

2. A LaTeX reference that can be inserted in a text file together with the proper LaTeX code for the creation of the corresponding hyperlink. An example is the following:
(\cite{Deconstructing-the-Laws-of-Logic-Clark-2008a}: \href{x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=2}{27})
3. A MediaWIki internal link to the wiki page of the source, followed by an external link to the PDF file itself. An example is the following:
([[Deconstructing the Laws of Logic - Clark]]: [x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=2 27]) 
4. A DEVONthink url

How to use this AppleScript

You should run the AppleScript when you read a PDF file in Skim and you want to make a reference to the current page. Additionally, a TextMate file should be opened. After the execution you can select from a menu which kind of reference you would like to be created. All the necessary numbers for the hyperlinks and the references are automatically created with the help of the fifth note. You can see this AppleScript in action in the following video:



The AppleScript code is the following:
--2011-04-05
--http://organognosi.blogspot.com

tell application "Skim"
    activate
    set numberOfNote5 to (get text for note 5 of page 1 of document 1) as string
   
    set RefType to my chooseRefType({"Latex for MediaWiki", "Latex", "MediaWiki", "DEVONthink link"})
    if RefType is 0 then return
   
    tell document 1
        set currentPageNumber to get index of current page
        set currentPageNumberText to currentPageNumber as text
        set pageDevonThinkNumber to currentPageNumber - 1
        set pageDevonThinkNumberText to pageDevonThinkNumber as text
        set DevonThinkLink to get text of note RefType of page 1
        set theRealPage to currentPageNumber + numberOfNote5 as string
       
        tell application "TextMate"
            activate
            if RefType is 1 then
                insert DevonThinkLink
                delay 1
                tell application "System Events"
                    key code 123
                    key code 123
                end tell
                delay 1
                insert pageDevonThinkNumberText & " " & theRealPage
                tell application "System Events"
                    key code 124
                    key code 124
                end tell
            else if RefType is 2 then
                insert DevonThinkLink
                delay 1
                tell application "System Events"
                    key code 123
                    key code 123
                    key code 123
                    key code 123
                end tell
                delay 1
                insert pageDevonThinkNumberText
                tell application "System Events"
                    key code 124
                    key code 124
                end tell
                delay 1
                insert theRealPage
                tell application "System Events"
                    key code 124
                    key code 124
                end tell
            else if RefType is 3 then
                insert DevonThinkLink
                delay 1
                tell application "System Events"
                    key code 123
                    key code 123
                end tell
                delay 1
                insert pageDevonThinkNumberText & " " & theRealPage
                tell application "System Events"
                    key code 124
                    key code 124
                end tell
            else if RefType is 4 then
                insert DevonThinkLink
                delay 1
                tell application "System Events"
                    key code 51
                end tell
                delay 1
                insert pageDevonThinkNumberText
               
            end if
        end tell
       
    end tell
   
   
   
end tell

on chooseRefType(typeList)
    tell application "Skim"
        set theResult to choose from list typeList with prompt "Reference type:"
        if theResult is false then return 0
        set refTypeNumber to theResult as string
        if refTypeNumber is "Latex for MediaWiki" then
            return 1
        else if refTypeNumber is "Latex" then
            return 2
        else if refTypeNumber is "MediaWiki" then
            return 3
        else if refTypeNumber is "DEVONthink link" then
            return 4
        end if
    end tell
    return RefType
end chooseRefType

No comments: