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/09

How to create hypermedia notes during your lectures!

There are some apps, which combine the features of a note taking and a voice recording app but in a very distinctive way. Specifically, they have the ability to continuously synchronize the recorded audio with your notes. As a result, each word acts as a link to the time point of the recorded audio at which it was written! Obviously this makes navigating a long lecture fast and easy and after a while you will start to appreciate the power of another kind of link!

Currently, I use "AudioNote" for taking my hypermedia notes mainly because there is a version of it both for iOS and Mac OS X. Consequently, I can read my notes and hear the synced audio in all my platforms. An other app with a somewhat more polished interface and richer organizational abilities is "Notability" but you can you use it only in your iPhone or your iPad.

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.