Showing posts with label Skim. Show all posts
Showing posts with label Skim. Show all posts

2011/06/10

Export Skim notes according to their highlight colors

Adam Cronkright mentioned, in a thread in the Skim forum, that he uses different colors for highlighting various sections of a PDF, which have a common characteristic (e.g. author's points he agrees with, points he disagrees with, good phrases...). His problem is that he would like to have an efficient way to organize these different categories of notes and Skim's present features does not help him much to this end.

I think that a way to solve this problem is to use a specialized app for note management and an AppleScript, which exports Skim notes according to their color. So I found a reason to write an additional AppleScript or actually two!

The first is a simplified version, which has only one prerequisite for execution. Particularly, you need to use one or more of the following colors: ice, honey drew, flora, lemon, cantaloupe, silver, which are shown below.


You can change a color in the Favorite Colors by dragging a new color from the Color Panel (Tools> Show Colors) and drop it on the Favorite Colors toolbar item. Hold down the Option key to add a new color. You can remove a color from the Favorite Colors by dragging it to the Trash (from Tips and Tricks page in Skim's wiki).

Each color in Skim is represented as a list of four numbers (red, green, blue, alpha). The fourth number is constant (65535). For example, the ice color is represented by the list  {26214, 65535, 65535, 65535}. So you can change the hardwired colors in the scripts if you know the corresponding RGB (red, green, blue) code in 16-bit format for your preferred colors. Then you can add it in in the chooseColor subroutine (see the AppleScript below). 

When you execute the script the following windows will open consecutively:


You can choose more than one colors by pressing cmd + click.



If you choose "Some" then you will be asked to give the range of pages from which the notes will be extracted.


 

The result is sent to the clipboard. The code is the following:
--2011-06-10
--http://organognosi.blogspot.com/
tell application "Skim"
    set the clipboard to ""
    set numberOfPages to count pages of document 1
    activate
    set myColorCodes to my chooseColor()
    display dialog "Do you want to export all the notes or some of them?" buttons {"All", "Some"} default button 1
    set answer to button returned of the result
   
    if answer is "All" then
        set firstPage to "1" as number
        set lastPage to numberOfPages
        set the clipboard to "Skim notes" & return
    else
        display dialog "Give the number of the first page." default answer ""
        set firstPage to text returned of the result as number
       
        display dialog "Give the number of the last page" default answer ""
        set lastPage to text returned of the result as number
    end if
   
    repeat with currentPage from firstPage to lastPage
        set pageNotes to notes of page currentPage of document 1
        exportPageNotes(pageNotes, currentPage, myColorCodes) of me
    end repeat
   
end tell

on exportPageNotes(listOfNotes, pageForProcessing, myColorCodes)
    tell application "Skim"
       
        set currentPDFpage to pageForProcessing
        repeat with coloredNote in listOfNotes
           
            repeat with i from 1 to the count of myColorCodes
                if color of coloredNote is item i of myColorCodes then
                    set noteText to get text for coloredNote
                   
                    set the clipboard to (the clipboard) & noteText & return & return
                end if
            end repeat
        end repeat
       
    end tell
end exportPageNotes

on chooseColor()
    set selectedColors to (choose from list {"ice", "honey drew", "flora", "lemon", "cantaloupe", "silver"} with prompt ("Choose the color of notes for exporting (you can select multiple colors):") default items {"lemon"} with multiple selections allowed)
   
    set colorCodes to {}
    set noteColor to ""
    repeat with noteCol in selectedColors
        set noteColor to noteCol as text
        if noteColor is "ice" then
            set end of colorCodes to {26214, 65535, 65535, 65535}
        else if noteColor is "honey drew" then
            set end of colorCodes to {52428, 65535, 26214, 65535}
        else if noteColor is "flora" then
            set end of colorCodes to {26214, 65535, 26214, 65535}
        else if noteColor is "lemon" then
            set end of colorCodes to {65535, 65535, 2, 65535}
        else if noteColor is "cantaloupe" then
            set end of colorCodes to {65535, 52428, 26214, 65535}
        else if noteColor is "silver" then
            set end of colorCodes to {52428, 52428, 52428, 65535}
        end if
    end repeat
   
    return colorCodes
end chooseColor

The second AppleScript is that which I use and is quite more complicated. As you may know, my preferred program for managing notes is MediaWiki so the AppleScript's result is customized for import in a MediaWiki page.

Some additional features of this AppleScript are the following:
  • a hyperlink to the exact PDF page is created for each exported note
  • the annotation's date and time are added at the end of each exported note
  • the notes from each page are separated by a line 
  • the extended text of the note is exported as well
  • the first five notes of the first page are not exported
  • the written page numbers should be given in the dialog windows

If you want to use this AppleScript you need firstly to create the five Skim notes in the first PDF page as I describe in my 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.

The code is the following:


--2011-06-10
--http://organognosi.blogspot.com/
tell application "Skim"
    set the clipboard to ""
    set numberOfNote5 to (get text for note 5 of page 1 of document 1) as string
    set pdfTitle to get (extended text of note 4) of page 1 of document 1 as string
    set numberOfPages to count pages of document 1
   
    activate
    set myColorCodes to my chooseColor() --εκτός των loops πρέπει να βρίσκεται, μια φορά το θέτεις
   
    display dialog "Do you want to export all the notes or only some of them?" buttons {"All", "Some"} default button 1
    set answer to button returned of the result
   
    if answer is "All" then
        set firstPage to "1" as number
        set lastPage to numberOfPages
        set the clipboard to "===Skim notes===" & return
    else
        display dialog "Give me the written number of the first page." default answer ""
        set firstPageWritten to text returned of the result as number
        set firstPage to firstPageWritten - numberOfNote5 as number
       
        display dialog "Give me the written numbers of the last page" default answer ""
        set lastPageWritten to text returned of the result as number
        set lastPage to lastPageWritten - numberOfNote5 as number
       
        set the clipboard to (the clipboard) & "Notes from \"[[@" & pdfTitle & "]]\" (pages " & firstPage & " - " & lastPage & ") <br />" & return
       
    end if
   
    repeat with currentPage from firstPage to lastPage
        --special provision for page 1
        if currentPage is 1 then
            set pageNotes to notes of page 1 of document 1
            set notesAfter5 to items 6 thru -1 of pageNotes
           
            exportPageNotes(notesAfter5, currentPage, myColorCodes) of me
        else
            set pageNotes to notes of page currentPage of document 1
           
            exportPageNotes(pageNotes, currentPage, myColorCodes) of me
        end if
    end repeat
   
end tell

on exportPageNotes(listOfNotes, pageForProcessing, myColorCodes)
    tell application "Skim"
        set numberOfNote5 to (get text for note 5 of page 1 of document 1) as string
        set pdfTitle to get (extended text of note 4) of page 1 of document 1 as string
        set numberOfPageNotes to count notes of page pageForProcessing of document 1
        set theWrittenPage to pageForProcessing + numberOfNote5 as string
        set pdfDevonThinkLink to (get text for note 4 of page 1 of document 1) as string
        set pdfDevonThinkLinkWihtoutZero to (text 1 thru ((length of pdfDevonThinkLink) - 1) of pdfDevonThinkLink) as string
       
        repeat with coloredNote in listOfNotes
           
            repeat with i from 1 to the count of myColorCodes
                if color of coloredNote is item i of myColorCodes then
                    set pdfText to get text for coloredNote
                    set pdfText2 to get extended text of coloredNote as text
                    set fullNoteText to pdfText & " " & pdfText2
                   
                    set annotationDate to modification date of coloredNote as text
                   
                    set pageForDevonThinkLink to pageForProcessing - 1
                   
                    --for use with MediaWiki semantic annotations
                    set firstCharacter to get the character 1 of fullNoteText
                    if firstCharacter = "[" then
                        set endofNote to "]]]"
                    else
                        set endofNote to "]"
                    end if
                   
                    set textAfterFullNoteText to "[" & pdfDevonThinkLinkWihtoutZero & pageForDevonThinkLink & " p. " & theWrittenPage & endofNote & " <small>(" & annotationDate & ")</small>"
                    set textForTextMate to fullNoteText & " " & textAfterFullNoteText
                    set textForTextMate2 to replaceText(textForTextMate, "missing value", "") of me
                    set textForTextMate3 to replaceText(textForTextMate2, " ()", "") of me
                   
                    set the clipboard to (the clipboard) & textForTextMate3 & return
                   
                end if
            end repeat
        end repeat
       
        set theSeperationLine to ""
        repeat with coloredNote in listOfNotes
            if numberOfPageNotes > 0 then
                repeat with i from 1 to the count of myColorCodes
                    if (color of coloredNote is item i of myColorCodes) then
                        set theSeperationLine to "----" & return
                        exit repeat
                    end if
                end repeat
            end if
        end repeat
        set the clipboard to (the clipboard) & theSeperationLine
    end tell
end exportPageNotes

on replaceText(thisText, searchString, replacementString)
    set AppleScript's text item delimiters to the searchString
    set the itemList to every text item of thisText
    set AppleScript's text item delimiters to the replacementString
    set thisText to the itemList as string
    set AppleScript's text item delimiters to {""}
    return thisText
end replaceText

on chooseColor()
    set selectedColors to (choose from list {"ice", "honey drew", "flora", "lemon", "cantaloupe", "silver"} with prompt ("Choose the color of notes for exporting (you can select multiple colors):") default items {"lemon"} with multiple selections allowed)
    --selectedColors is a list of lists
    set colorCodes to {}
    set noteColor to ""
    repeat with noteCol in selectedColors
        set noteColor to noteCol as text
        if noteColor is "ice" then
            set end of colorCodes to {26214, 65535, 65535, 65535}
        else if noteColor is "honey drew" then
            set end of colorCodes to {52428, 65535, 26214, 65535}
        else if noteColor is "flora" then
            set end of colorCodes to {26214, 65535, 26214, 65535}
        else if noteColor is "lemon" then
            set end of colorCodes to {65535, 65535, 2, 65535}
        else if noteColor is "cantaloupe" then
            set end of colorCodes to {65535, 52428, 26214, 65535}
        else if noteColor is "silver" then
            set end of colorCodes to {52428, 52428, 52428, 65535}
           
        end if
    end repeat
   
    return colorCodes
end chooseColor

I hope this AppleScript will help Adam! Anyway, your post was an inspiration for me. Finally, I would like to thank Martin who informed me about it.

2011/05/20

Sync PDF page numbers between Skim's snapshot window and main window.

A quite useful feature of Skim is that "you can take "snapshots" of important sections (like the bibliography section) of a PDF document, to keep them on your screen for easy reference. This way you don't have to leaf back to the section every time you want to see it" (Skim help file).

But the snapshot windows are just for viewing the material. For example, you cannot highlight or select text in them. In order to make annotating of these pages easier I wrote an AppleScript, which instantly shows you in the main window, the current page in the snapshot window. When you finish annotating this page you can go back to the previous page by using the cmd + [ shortkey or by triggering the corresponding gesture (I use the "three finger left" gesture for this task).

If you use more than one snapshot windows from the same document, after selecting the page that you want to annotate in one of them, you need to click one time all the remaining snapshots windows, before running the AppleScript.

The AppleScript code is the following:

--2011-05-20
--http://organognosi.blogspot.com

set nameSnapshot to ""
tell application "Skim"
    set frontNameDocument to name of document 1
    set windowsNames to get the name of windows
   
    repeat with x from 1 to count of items of windowsNames
        set windowName to item x of windowsNames
        if windowName contains frontNameDocument & " —" then
            set nameSnapshot to windowName
        end if
    end repeat
   
    set position to offset of "—" in nameSnapshot
    set AppleScript's text item delimiters to ""
    set stg_numberPage to characters (position + 7) thru -1 of nameSnapshot as text
    set numberPage to stg_numberPage as number
   
    go document 1 to page numberPage of document 1
   
end tell

2011/05/01

Delete the duplicate Skim notes

With the following AppleScript you can delete the Skim notes which have exactly the same text in each page of a PDF file.

--2011-05-01
-- http://organognosi.blogspot.com

tell application "Skim"
    --the following code deletes the note text which is repeated one or more times in a PDF page
    set numberOfMyPages to count pages of document 1
    repeat with currentPage from 1 to numberOfMyPages
        set numberOfPageNotes to count notes of page currentPage of document 1
        set textOfCurrentPageNotes to text of notes of page currentPage of document 1 as list
       
        repeat with currentNoteNumber from 1 to numberOfPageNotes
            set noteText to (get text for note currentNoteNumber of page currentPage of document 1) as text
            set offsetPositionsOfDuplicates to list_positions(textOfCurrentPageNotes, noteText, true) of me
            set the numberOfDuplicates to length of offsetPositionsOfDuplicates
            repeat with noteForTextDeletion from 2 to numberOfDuplicates
               
                set noteNumber to item noteForTextDeletion of offsetPositionsOfDuplicates
                delete text of note noteNumber of page currentPage of document 1
            end repeat
        end repeat
    end repeat
    --the following code deletes the empty notes   
    set numberOfMyPages to count pages of document 1
    set numberOfAlltheNotes to count notes of document 1
    set indexesOfEmptyNotes to {}
    repeat with currentNote from 1 to numberOfAlltheNotes
        set noteText to (get text for note currentNote of document 1) as text
       
        if noteText is "" then
            set the end of the indexesOfEmptyNotes to currentNote as string
            set ABC to the length of indexesOfEmptyNotes
        end if
    end repeat
   
    repeat with x from 1 to ABC
        set indexNote to item x of indexesOfEmptyNotes as number
        set indexNote to indexNote - x + 1
        delete note indexNote of document 1
    end repeat
end tell

--the following subroutine is from Soghoian's AppleScript 1-2-3 book (p. 569)
on list_positions(this_list, this_item, list_all)
    set the offsetlist to {}
    repeat with i from 1 to the count of this_list
        if item i of this_list is this_item then
            set the end of the offsetlist to i
            if list_all is false then
                return item 1 of offset_list
            end if
        end if
    end repeat
   
    if list_all is false and offsetlist is {} then return 0
    return the offsetlist
end list_positions

2011/04/22

Count the words of a PDF file from Skim

Here is a small AppleScript for counting the words of a PDF file from Skim.

tell application "Skim"
    set PDFwords to 0
    set numberOfMyPages to count pages of document 1
   
    repeat with currentPage from 1 to numberOfMyPages
        set numberOfPageWords to count words of page currentPage of document 1
        set PDFwords to PDFwords + numberOfPageWords
    end repeat
   
    display dialog "Number of words: " & PDFwords buttons {"Cancel", "OK"} default button 2
end tell

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

2011/04/02

Go to the written page number of a PDF document

In my previous post "Latin page numbers, Arabic page numbers and the fifth Skim note" I described the logic behind the number in the fifth note. Now we can use this information in order to go to the written page number of a PDF document without doing any calculations. This proves quite convenient especially in the case of academic papers in which the written numbers are totally out of sync with the page numbers which are given by Skim.

The AppleScript which performs this function is the following:

--2011-04-02
--http://organognosi.blogspot.com

tell application "Skim"
    display dialog "Give the written page number:" default answer "" buttons {"Cancel", "OK"} default button 2
    set writtenNumber to text returned of the result as integer
   
    set numberNote5 to (get text for note 5 of page 1 of document 1)
    set numberInThePDF to writtenNumber - numberNote5
    go document 1 to page numberInThePDF of document 1
end tell


2011/04/01

Latin page numbers, Arabic page numbers and the fifth Skim note

I have observed that my ebooks and papers which are in PDF format can be separated in one of the following three groups according to the relation between the page numbers that are given by Skim and the correspoding written numbers in the potentially printed PDF pages. 

The first group contains the PDF files in which these two numbers coincide for any given page.  In this case there is just the number zero in the fifth note in the first PDF page. This is the simplest case and an example of such a document is shown in the following image.


The second group contains ebooks in which Latin numbers are used in a number of pages such as in its table of contents. In this case I put in the fifth note the negative total number of pages that precede the first PDF page with the written Arabic number 1. For example lets say that an ebook has its cover in the first PDF page, followed by six pages with Latin numbers. As a result the first PDF page with the Arabic number 1 is the eighth PDF page and the number -7 is written in the fifth note. In the following image you can see a page from the aforementioned ebook.


By the way I do not find any value in the use of Latin numbers in electronic documents. To the contrary it makes the navigation of PDF files more difficult and cumbersome. One way to solve this problem is to move all the pages with Latin numbers and the cover at the end of the file. However, if you create these notes in your PDF files there is an alternative way of overcoming the problems which are caused by this relic of publishing tradition.

Finally the third group contains papers from academic journals in which the written page numbers are totally out of sync with the page numbers which are given by Skim. In this case I put in the fifth note the written number in the first PDF page decreased by one. An example of such a document is shown in the following image.


If there is an extra page with journal and paper information at the start of the document then you should substract by two.



In my next posts I will present what can be achieved with the help of the fifth note. 

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".

2011/03/24

How to reveal the front Skim PDF document in Finder and in DEVONthink

You can use the following AppleScript to reveal the front Skim PDF document in Finder:

tell application "Skim"
    set FilePath to get the file of front document
    tell application "Finder"
        activate
        reveal FilePath
    end tell
end tell
You can use the following AppleScript to reveal the front Skim PDF document in DEVONthink:

tell application "Skim"
    set the xDEVONthinkLink to (get text for note 4 of document 1) as string
    set customUUID to text 21 thru -8 of xDEVONthinkLink as string
end tell

tell application "DEVONthink Pro"
    activate
    tell database "MySources"
        set myPDF to get record with uuid customUUID
        open tab for record myPDF
        tell application "System Events"
            tell process "DEVONthink Pro" to click menu item "Reveal" of menu 1 of menu bar item "Data" of menu bar 1
        end tell
    end tell
    close document window 1
end tell
In order for the last AppleScript to work properly, you need to have the DEVONthink URL in the fourth Skim note of the first page of the PDF in the following form:

x-devonthink-item://648847AF-4714-4328-916C-6169A6389124?page=0

In my post "How to put DevonThink links in Skim note" I describe how this can be done automatically. 

Moreover you need to adjust appropriately the name of the DEVONthink database  in the line:
    tell database "MySources" 

2011/03/09

How to convert a Mac-Unix style path to a Windows style path from Skim

Sometimes, I want to open a PDF file in my Windows virtual machine. To make things faster I wrote an AppleScript which converts the PDF file path of the front Skim window to its proper Windows style and then the converted path is sent to the clipboard.
As a result, all I have to do after the conversion is to paste the new path to the "File" field of the "Open" window in Adobe Acrobat Pro in Windows.

In order for this AppleScript to work properly, you need to customize the variable "WinPath" with the name and the drive letter of your hard drive.

The AppleScript code is the following:
tell application "Skim"
    set FilePath to get the path of front document
    set my text item delimiters to "/"
    set FilePath to text items of FilePath
    set my text item delimiters to "\\"
    set FilePath to (FilePath as text)
    set WinPath to "Z:\\MBProSystem" & FilePath
    set the clipboard to WinPath
end tell

2011/03/07

Automated creation of a LaTeX compatible citation only from Skim! (with hyperlink included)

In the post "DevonThink links in Skim notes and AppleScript" I presented how you can create to a PDF file a number of Skim notes with various versions of references to itself. An example of these notes is shown below:


Then you can insert manually the BibTeX cite command in the fist and the second note.


Now you are ready to capitalize on these four little notes!

The first way was presented in the post "Automated summary creation linked with the source pfd file" where the respective AppleScript use the fourth note:
 set pdfDevonThinkLink to (get text for note 4 of page 1 of document 1) as string
In the AppleScript of this post the second note will be used.

As you understand the numbering of these notes plays a fundamental role in the effective use of these AppleScripts. For this reason 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 (2011-04-05, an alternative solution is to use the AppleScript in my 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").

One of the most important reasons for which I have chosen to write my essays using LaTeX is that it makes possible the creation of rich hypertexts. By rich I mean that the final PDF document can have all the sorts of different kinds of links as you can see in the lower part of my mind map "The many faces of links". In order to create these links you should use the Hyperref package.

If you are accustomed to the LaTeX markup code you will recognize that the second note includes a proper citation as it is required by the Hyperref package:

(\cite{Deconstructing-the-Laws-of-Logic-Clark-2008a}: \href{x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=}{})
The only things that are missing from the above citation are two numbers: the number for the DevonThink link and the the number of the referred page.

Now lets say that you would like to refer to the 27th page of the paper which is the third page of the PDF file. From now on you do not have to manually paste the necessary code and the appropriate numbers in your txt file but an AppleScript can do it for you!

There is only one but... you want the number that is shown in your text to be 27 but the number which is attached to the DevonThink link to be 2 (3-1: if you do not know why, read my post It's all about hyperlinks!). My AppleScript has the ability to recognize in which page you currently are but it cannot recognize the written number in the page! So you will have to enter it manually.

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

display dialog "Give the number which is written in you current page:" default answer "" buttons {"Cancel", "OK"} default button 2
set writtenNumber to text returned of the result as text

tell application "Skim"
    activate
   
    tell document 1
        set currentPageNumber to get index of current page
        set pageDevonThinkNumber to currentPageNumber - 1
        set pageDevonThinkNumberText to pageDevonThinkNumber as text
        set DevonThinkLink to get text of note 2 of page 1
       
        tell application "TextMate"
            activate
            insert DevonThinkLink
            tell application "System Events"
                key code 123
                key code 123
                key code 123
                key code 123
            end tell
            delay 0.5
            insert pageDevonThinkNumberText
            tell application "System Events"
                key code 124
                key code 124
            end tell
            delay 0.5
            insert writtenNumber
        end tell
    end tell
end tell

If you do not want to write even this number you can create a fifth note which will have only the written number of the first page and then the AppleScript can compute the rest.

--2011-03-07
--http://organognosi.blogspot.com

tell application "Skim"
    activate
   
    tell document 1
        set currentPageNumber to get index of current page
        set pageDevonThinkNumber to currentPageNumber - 1
        set pageDevonThinkNumberText to pageDevonThinkNumber as text
        set DevonThinkLink to get text of note 2 of page 1
        set writtenNumberOfFirstPage to (get text for note 5 of page 1) as string
        set currentPageWrittenNumber to currentPageNumber + writtenNumberOfFirstPage - 1 as string
       
       
        tell application "TextMate"
            activate
            insert DevonThinkLink
            tell application "System Events"
                key code 123
                key code 123
                key code 123
                key code 123
            end tell
            delay 0.5
            insert pageDevonThinkNumberText
            tell application "System Events"
                key code 124
                key code 124
            end tell
            delay 0.5
            insert currentPageWrittenNumber
        end tell
    end tell
end tell

Finally the easiest case is when the page numbers of the PDF file and the printed book coincide. In this case you can still use the above AppleScript if you write in the fifth note the number 1. If you do not want to use a fifth note the AppleScript is the following:

--2011-03-07
--http://organognosi.blogspot.com

tell application "Skim"
    activate
   
    tell document 1
        set currentPageNumber to get index of current page
        set pageDevonThinkNumber to currentPageNumber - 1
        set pageDevonThinkNumberText to pageDevonThinkNumber as string
        set currentPageNumberText to currentPageNumber as string
        set DevonThinkLink to get text of note 2 of page 1
       
       
        tell application "TextMate"
            activate
            insert DevonThinkLink
            tell application "System Events"
                key code 123
                key code 123
                key code 123
                key code 123
            end tell
            delay 0.5
            insert pageDevonThinkNumberText
            tell application "System Events"
                key code 124
                key code 124
            end tell
            delay 0.5
            insert currentPageNumberText
        end tell
    end tell
end tell
Before you execute any of the above AppleScripts you should have a TextMate document opened. Moreover the cursor should be at the point in which you want the citation to be inserted.

2011-04-05
There is an improved version of the above AppleScript in my post "Automated creation of references with hyperlinks from Skim"


2011/03/06

Open a DevonThink hyperlink directly to Skim

I use a QuicKeys macro in order to open a DevonThink PDF hyperlink directly to the specific PDF page in Skim. In the following image you see the required steps of the macro. In the third step you should put the whole AppleScipt from my previous post:  "Go from the current PDF page in DevonThink to the same page in Skim - AppleScript" 


Then you can assign a specific gesture (for example "four finger click") using BetterTouchToul to the used hot key (option + cmd + F1) for the macro and you are done! Now you can bypass DevonThink and read the linked PDF page in Skim immediately!

You can download this macro from here (right click + Sava as)

 Automation rules!

Go from the current PDF page in DevonThink to the same page in Skim

I prefer reading my PDF files in Skim. Moreover all my read PDF files are inside DevonThink databases and all my PDF hyperlinks lead to DevonThink. As a result I regularly used the "Open in external viewer" function of DevonThink. Unfortunately the PDF is opened in the first page so you have to manually go to the desired page. If you need to do this a lot of times after a while it becomes annoying. So I wrote an AppleScript which automates this procedure :-).

The AppleScript is the following:
tell application "DEVONthink Pro"
    set pdfFile to the content record of the think window 1
    set RecordLink to the reference URL of pdfFile
    set PdfPage to current page of the think window 1
    set DevonThinkLink to RecordLink & "?page=" & PdfPage
    set the clipboard to DevonThinkLink
    set PdfPath to get the path of pdfFile
    set PdfPath to (POSIX file PdfPath) as Unicode text

   
   
    tell application "Skim"
        open file PdfPath
        set PdfPage to PdfPage + 1
        go document 1 to page PdfPage of document 1
    end tell
end tell

2011/02/21

Automated summary creation linked with the source PDF file

One of the great characteristics of Skim highlights is that they capture automatically the highlighted text  in a newly created note.


Moreover you can export these notes in a separate txt or rtf file.




As a result an approximation of a summary is created if you highlight the appropriate text passages.




Additionally if you have created the Skim notes with the DevonThink links as I described in the post "DevonThink links in Skim notes and AppleScript" you can use another AppleScript in order to have a properly formatted hyperlink from every highlighted text to the exact pdf page of the paper or book.


When you copy this text to the respective wiki page of the paper or book you will have a nice hypertext between your summary and the source pdf file.


You can see the seamless integration between the summary and the pdf in the following YouTube video.

The AppleScript code is the following (updated):

 tell application "Skim"
    set pdfDevonThinkLink to (get text for note 4 of page 1 of document 1) as string
    set pdfDevonThinkLinkWihtoutZero to (text 1 thru ((length of pdfDevonThinkLink) - 1) of pdfDevonThinkLink) as string
  
    set allMyPages to pages of document 1
    set numberOfMyPages to length of allMyPages as integer
  
  
    tell application "TextMate"
        activate
        tell document 1
            insert "===Skim notes===
"
        end tell
    end tell
  
    repeat with currentPage from 0 to numberOfMyPages
        set pageNotes to notes of page currentPage of document 1
        set numberOfPageNotes to length of pageNotes as integer
      
        repeat with currentNoteNumber from 1 to numberOfPageNotes
            set pdfText to (get text for note currentNoteNumber of page currentPage of document 1) as string
          
            set pageForDevonThinkLink to currentPage - 1
            set the clipboard to pdfText
          
            tell application "TextMate"
                tell document 1
                    insert (the clipboard) & " [" & pdfDevonThinkLinkWihtoutZero & pageForDevonThinkLink & " p. " & currentPage & "]

"
                end tell
            end tell
        end repeat
    end repeat
end tell
In order for the script to work you need to have TextMate installed in your Mac and an empty txt file open.

2011/02/20

How to put DevonThink links in Skim notes


For every book or paper that I read I create a new page in my wiki. The name of this page is created under the following template: Title - Author, for example "Deconstructing the Laws of Logic - Clark". In this page I keep all my notes and my thoughts concerning this paper. The pdf file is inside a DevonThink database. When I am reading a pdf I want to be able to use the DevonThink link without leaving Skim. To this end I wrote an AppleScript, which creates in the first page of a pdf four Skim notes, containing four different ways of constructing references using DevonThink links.
The fourth note is the simplest and contains the DevonThink url (x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=0). Its extended text contains the title of the wiki page. 

The third note contains a MediaWIki internal link to the wiki page of this pdf followed by an external link to the pdf file itself.

The second note contains the necessary Latex code for creating a proper bibliography reference and a link to the exact pdf page using the hyperref package. The only things that are missing from the above code are the cite key (between the opening parenthesis and the colon) and the page numbers. As an example the complete second note is the following: 

(\cite{Deconstructing-the-Laws-of-Logic-Clark-2008a}: \href{x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=}{})

As you can notice the cite key "Deconstructing-the-Laws-of-Logic-Clark-2008a" is quite long. I have chosen this because I want to recognize the reference just by looking in its cite key and not by trying to remember for example which paper Clark wrote on 2008...

The code for a bibliography reference to the third page of this paper which is in the 27th page of the Philosophy Journal is the following:

(\cite{Deconstructing-the-Laws-of-Logic-Clark-2008a}: \href{x-devonthink-item://CDEC17B7-1EEE-42E1-B8C9-86A24C172BF3?page=2}{27})

The first note contains the necessary MediaWiki code for creating a link to the excact pdf page which is compatible with LaTeX whenever you want to export the wiki text to Latex (more about this in a quite distant in time post...)

Now every time I want to create a link to a pdf file everything is at hand in one of these notes! 

The AppleScript code which makes all the above possible is the following: 
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
            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}
            end tell
            save document 1
            delay 1
            close document 1
           
        end tell
    end repeat
end tell
2011-04-02 
In my 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" there is an improved version of the above AppleScript. The newer one solves a problem which appears when you want a third AppleScript to use the aforementioned Skim notes like the AppleScript in my post "Automated creation of a LaTeX compatible citation only from Skim! (with hyperlink included)". Moreover it creates a fifth note for which there is detailed information in my post "Latin page numbers, Arabic page numbers and the fifth Skim note".

2011/02/15

A road map for my blog - The many faces of links

In the following mind map you can see the various kinds of links that I am able to use and the respective programs that are required in order to create each of them. Moreover I have added some hyperlinks in the nodes for which I have posted relevant information.



From A Digital Workflow for Academic Research

You can download this mind map in its native Mind Manager file format from here  and as a PDF from here (right click + Save as).

Finally, you can view this mind map as a roadmap for my blogspots... post by post I will try to present how you can create and use these different ways of cross-linking your thoughts, notes, writings and also your sources into an integrated whole!  

2011/02/12

Some tools of the trade

I use the following hardware:
  • a MacBook Pro 17in
  • a MacMini (as a server for my wikis and my ebooks library)
  • an iPad
  • a Time Capsule
  • an iPhone 3G
  • several external hard drives (for backup)
  • a 27in LG monitor

In my academic workflow I use the following programs:
  • Skim: for reading papers and books (in pdf format)
  • Calibre: for organizing all my ebooks (read and unread)
  • DevonThink: for organizing everything that I have read
  • BibDesk: for reference management and automated bibliography creation
  • MediaWIki: for notes management
  • TextMate and LaTex: for writing my papers
  • AppleScript: for automating my workflow