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. 

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

The roadmap of my blog on-line in MindMeister

Yesterday, I found a new on-line mind mapping tool, named MindMeister and I uploaded there the mind map about the various kinds of links that I use in my workflow. Moreover it is now embedded in the original post "A road map for my blog - The many faces of links" and you can navigate it also from here. I think it deserves a second post in this, greatly improved and interactive form!


How to easily assign shortkeys and gestures to AppleScripts

In my daily workflow I use a significant number of AppleScripts, as you will have understoond from my previous posts :-). So it is handy for me to assign shortkeys to some of them. For this purpose I use the FastScripts utility.  Although it is not a commercial app, it gives you for free up to 10 keyboard shortcuts.
 
After the previous assignments you are able to trigger the execution of AppleScripts using customized gesture definitions with the help of BetterTouchTool app.

In the following screenshot you can see some of my Skim gestures:


How to automatically embed hyperlinks into citations and bibliographical entries of a downloaded PDF document! Part III

In the last post of this series I present how the embedding of hyperlinks is made in a sample PDF file. A prerequisite for the following actions it to have already created one or more link dictionaries (if you do not know how, read part II for detailed instructions and part I for more general related information).

Let's say that you have the PDF file opened in Skim. Then you should open it in Adobe Acrobat Pro in your Windows virtual machine. To make things faster you can have the Windows formatted path of this file in your clipboard by executing the AppleScript which I wrote in my post: "How to convert a Mac-Unix style path to a Windows style path from Skim".

In the following sreenshots you can see the required steps:




 

2011/03/11

How to automatically embed hyperlinks into citations and bibliographical entries of a downloaded PDF document! Part II

How to create the dictionaries

Firstly your ebooks and epapers should be inside inside a DevonThink database. Moreover each source should have its respective record in BibDesk. The "local URL" field of each record should have the DevonThink URL of the source. If you do not know how to do this you can read my post "How to connect a PDF file inside DevonThink with its record in BibDesk". Finally you should select the records in BibDesk which will constitute the records of the dictionary and you should have one TextMate txt file open. Now you are ready to execute either the AppleScript for the creation of the link dictionary with the titles or for the second kind of dictionary.

The AppleScript code for the link dictionary with the titles is the following:
--2011-03-11
--http://organognosi.blogspot.com
--Works with AutoBookmark 3.7
tell application "BibDesk"
    set these_items to the selection of document 1
    if these_items is {} then error "Please select some contents."
       
    repeat with this_item in these_items
        set DevonThinkLink to the linked URL 1 of this_item
        set PDfTitle to the value of the field "Title" of this_item
        set keywords of this_item to keywords of this_item & "," & " title link"
        set DictionaryLinkEntry to PDfTitle & tab & "uri:" & DevonThinkLink & "
"
        tell application "TextMate"
            activate
            insert DictionaryLinkEntry
        end tell
    end repeat
end tell

A sample from the text which can be created is shown below:


The AppleScript code for the link dictionary with author-year compinations is the following:
--2011-03-11
--http://organognosi.blogspot.com

tell application "BibDesk"
    set these_items to the selection of document 1
    if these_items is {} then error "Please select some contents."
   
    repeat with this_item in these_items
        try
            set AuthorLink to the last name of the first author of this_item
            set firstNameLink to the first name of the first author of this_item
            set AbbrNormName to abbreviated normalized name of the first author of this_item
           
            set YearLink to the publication year of this_item
            set DevonThinkLink1 to the linked URL 1 of this_item
            set DictionaryLinkEntry to AuthorLink & " " & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
            set DictionaryLinkEntry2 to AuthorLink & " (" & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
            set DictionaryLinkEntry3 to AuthorLink & " [" & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
            set DictionaryLinkEntry4 to AuthorLink & ", " & firstNameLink & " (" & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
            set DictionaryLinkEntry5 to AbbrNormName & " " & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
            set DictionaryLinkEntry6 to AbbrNormName & " (" & YearLink & tab & "uri:" & DevonThinkLink1 & "
"
           
            tell application "TextMate"
                activate
                insert DictionaryLinkEntry
                insert DictionaryLinkEntry2
                insert DictionaryLinkEntry3
                insert DictionaryLinkEntry4
                insert DictionaryLinkEntry5
                insert DictionaryLinkEntry6
            end tell
        end try
    end repeat
end tell
A sample from the text which can be created is shown below:


Now you are ready to go to Adobe Acrobat Pro and use the AutoBookmark plug-in. In the following screen shots you can see the detailed steps in order to create the new dictionaries.




In this step you should select the txt file which was created by one of the two AppleScripts
Now your link dictionary is ready.

How to automatically embed hyperlinks into citations and bibliographical entries of a downloaded PDF document! Part I

Nowadays, it is possible for a researcher to amass a huge number of electronic papers and books about his specialized area of interest. Naturally there are a lot of cross-references between these sources. The usual way of managing these files is the creation of a bibliographical database in one of the numerous relative programs like EndNote, Papers, JabRef and BibDesk. In this post I will try to present an exciting new way of "managing" your files which in a way makes managing them obsolete!

Specifically I created a workflow for embedding DevonThink hyperlinks into the very citations and bibliography entries of a PDF file. As a result when you want to read a cited paper or book you do not need to go to your bibliography manager program or even worse to the folder hierarchy of your hard drive in order to find the file. Instead you can just click the citation or the title or the author of the bibliography entry and the respective PDF file opens instantly! The magic of DevonThink hyperlinks in action!

The required tools/programs for this dream to come true are the following:
  1. Adobe Acrobat Pro for Windows
  2. AutoBookmark plug-in for Adobe Acrobat Pro
  3. A Windows virtual machine 
  4. DevonThink
  5. BibDesk
  6. TextMate
  7. Link dictionaries
  8. The AppleScripts for creating automatically the link dictionaries from BibDesk
More details about the workflow

AutoBookmark searches page text for occurrences of specific words or phrases and generates links annotations according to the user specifications. Link dictionary is a collection of search terms (words, phrases and etc.) and corresponding link actions. When it finds a search term from a dictionary it automatically creates a link annotation using a link action that is associated with it. Each search term should be unique within a link dictionary (excerpt from AutoBookmark help file). So you need to have an appropriate link dictionary so as the hyperlinks to the sources to be created automatically by AutoBookmark.

For our case I consider optimal the use of two different dictionaries each with its own advantages and disadvantages. The first contains  various possible forms of author-year citations e.g. Clark 2008, Clark (2008, Clark Stephen (2008, Clark S. 2008, Clark S. (2008. The advantage of this dictionary is that the matches are almost 100% unique. However the probability of the match is somewhat small because of the high variability in the way that the citations are made. The second contains the source titles. Now the situation is the complete opposite because you can very easily have false positive matches if the title is too generic but there is no case of a missing match if the title is adequately complex. 

In my next post I will describe how you can create the link dictionaries from your Mac.

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

How to connect a PDF file inside DevonThink with its record in BibDesk

I use BibDesk to manage and create my bibliographies but all my read and annotated PDF files are inside DevonThink. So I wanted an easy and fast way to connect the PDF files with their respective records in BibDesk. Technically I wanted to populate the "local URL" and "local File" columns of BibDesk. Consequently I wrote an AppleScript which does this job :-).

Moreover this AppleScript assigns the tag/keyword "Linked with DevonThink" to the record in which is applied. In order for this script to work properly you just have to select one PDF file in DevonThink and its respective bibliography record in BibDesk.

The AppleScript code is the following:

 --2011-03-08
--http://organognosi.blogspot.com
--the script works only for one PDF file per time

tell application "DEVONthink Pro"
    set this_item to the content record of think window 1
    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 PdfPath to (POSIX file PdfPath) as alias
  
    tell application "BibDesk"
        activate
        set these_items to the selection of document 1
        repeat with theBook in these_items
            add DevonThinkLink to linked URL of theBook
            add PdfPath to linked files of theBook
            set currentKeywords to get keywords of theBook as string
            if (currentKeywords is not "") then
                set delimiter to ", "
            else
                set delimiter to ""
            end if
            set keywords of theBook to (keywords of theBook & delimiter & "Linked with DevonThink")
        end repeat
    end tell
  
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/13

How to use DevonThink links in a MediaWiki page

MediaWiki supports out of the box a number of protocols for external linking such as HTTP, HTTPS, mailto, IRC. Additionally it gives you the possibility to add your own protocols by modifing the LocalSettings.php file under the root folder.

I have installed MAMP in order to use MediaWiki and lets say that my wiki is named "MyWiki". Then the path for this file in my file structure is (I use Snow Leopard):
/Applications/MAMP/htdocs/MyWiki/LocalSettings.php
So in order for MediaWiki to be able to understand DevonThink links you need to add the following line to the LocalSettings.php file:
$wgUrlProtocols[] = 'x-devonthink-item://';    

Then when you write in the edit mode of a MediaWiki page:

you just see

a nice hyperlink after saving. 

Now MediaWiki and DevonThink are perfectly integrated! See a short demonstration in the following video.




If you want to learn how the wiki text in the above video can be created automatically using Skim, AppleScript and Textmate read the following posts: