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