Showing posts with label hyperlink. Show all posts
Showing posts with label hyperlink. Show all posts

2011/05/31

Create MediaWiki links to local folders and files without any extension!

In my previous post "Embed AppleScripts in a MediaWiki page", I showed how an AppleScript, embedded in a HTML link, can be inserted in a MediaWiki page. A way that I use this MediaWiki feature is by creating links to local files and folders. Moreover, after executing the AppleScript, the files open with their assigned applications. Finally as you can see in the same post, the whole link syntax is quite complicated so I wrote an AppleScript, which creates automatically all the required code for the selected files and folders in Finder. The names of them should be in Latin characters.

The AppleScript code is the following:

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

tell application "Finder"
    set selectedItems to the selection
    if selectedItems is {} then error "Please select some contents."
    set the clipboard to ""
    repeat with selectedItem in selectedItems
        set selectedItem to selectedItem as string
        set encodedText to my encode_URL_string(selectedItem)
       
        set embeddedAppleScript to "<html>" & return & "<a href=\"" & "apple" & "script" & "://com.apple.scripteditor?action=new&script= tell%20application%20%22Finder%22%0D
%09open%20(alias%20%22" & encodedText & "%22)%0D" & return & "end%20tell\"l>" & selectedItem & "</a>" & return & "</html>"
       
        set the clipboard to (the clipboard) & embeddedAppleScript & "<br/>" & return
    end repeat
end tell

--Text handlers from Apple to encode the selectedItem string
property allowed_URL_chars : (characters of "$-_.+!*'(),1234567890abcdefghijklmnopqrstuvwxyz")
on encode_URL_string(this_item)
    set character_list to (characters of this_item)
    repeat with i from 1 to number of items in character_list
        set this_char to item i of character_list
        if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
    end repeat
    return character_list as string
end encode_URL_string

property hex_list : (characters of "0123456789ABCDEF")
on encode_URL_char(this_char)
    set ASCII_num to (ASCII number this_char)
    set x to item ((ASCII_num div 16) + 1) of hex_list
    set y to item ((ASCII_num mod 16) + 1) of hex_list
    return ("%" & x & y) as string
end encode_URL_char

2011/05/29

Embed AppleScripts in a MediaWiki page

You can embed an AppleScript in a MediaWiki page if you insert the script as the URL in a proper HTML link. Particularly, the HTML link syntax looks like this:
<a href="URL">Link text</a>
The AppleScript code should be converted in a format which is compatible with HTML URLs. For example, each space in the script should be replaced by the string %20, each tab by %09 and each enter by %0D. Moreover, the "applescript://" URL scheme will be used and the whole link should be within <html>, </html> tags.   Fortunately the whole conversion can be done automatically by an AppleScript or using the freeware AppleScriptHTML app.

Finally, raw HTML code is not allowed by default in a public wiki for security reasons but if you maintain a private wiki you can permit it by setting
$wgRawHtml = true;
in the LocalSettings.php file.

For example, suppose you want to embed the following AppleScript
tell application "Finder"
    open (alias "MBSystem:Users:MB:Downloads:")
end tell
which opens the "Downloads" folder in a Finder window. Then, you should write the following code in a MediaWiki page:
<html>
<a href="applescript://com.apple.scripteditor?action=new&script= tell%20application%20%22Finder%22%0D
%09open%20(alias%20%22MBSystem%3AUsers%3AMB%3ADownloads%3A%22)%0D
end%20tell"l>MBSystem:Users:MB:Downloads:</a>
</html>
and you will see the link, after saving the page.


Afterwards, every time you click the link an AppleScript editor window opens with the AppleScript code inside it, as is shown in the next image.

Now, you may press cmd + R (executes the script), cmd + W (closes the window) and cmd + D (without saving)!

In my next post, I will present how you can create automatically HTML links to local files and folders, with AppleScript code inside them, which can be embedded in a MediaWiki page.

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


2011/02/12

It's all about hyperlinks!

If I was forced to choose the single most important element of my workflow then my answer would be the creation and usage of hyperlinks. We are all accustomed of using hyperlinks in the World Wide Web but I have observed that the usage of them in the personal mode of working is quite rare.

A classic but somewhat outdated form of link is the bibliography reference that is commonly used in academic texts. Its main disadvantage is that you need a lot of time and energy to actually find and use the referred passage. Nowadays a different situation is possible by using hyperlinks.  

I chose to use MediaWiki, DevonThink and Latex because they make the cross-linkage of my notes, my sources and my writings very easy and fast.

Specifically lets say you have A and B wiki pages. If you want to create a hyperlink from A to B you just have to write [[B]] in the wiki text. The whole process is very well documented in the MediaWiki help page about links.

The respective linking process with DevonThink is not well known and I think it is quite important. I even believe this capability of DevonThink to be a reason for academic researchers to switch to Mac computers!

The DevonThink program assigns a custom Uniform Resource Locator (URL) for every file that is imported or indexed to it. An example of this URL is the following:

"x-devonthink-item://6632BE51-AEDF-42F9-9CFD-BFED462EBC33"

Moreover, in the case of a pdf file, a different URL is assigned to every single page of it. This URL takes the form:

"x-devonthink-item://BB2D2CDA-0BCA-4F72-8C8E-64B49CA12839?page=0"

As a result when you want to refer to the twenty fifth page of a pdf document you just have to use the URL:

"x-devonthink-item://BB2D2CDA-0BCA-4F72-8C8E-64B49CA12839?page=24"

Notice that the page number in the URL is 24 and not 25 as the index base that is used by DevonThink is zero and not one.

You can send this URL to the clipboard by clicking "Copy Page Link" in the contextual menu.



Then you can use this link in order to create a hyperlink to the exact pdf page! As a result all your bibliography references can be transformed to live links to the respective pages. No more you have to hunt down the source of a quotation!

There is only one but...

Not every word processor accepts the DevonThink links, the most prominent of them... Word.  This is an additional reason that I do not use Word...


Some programs that are fully compatible with the DevonThink links are the following:
In the above programs after you paste a DevonThink link you do not see the raw URL but the name of the linked file!
Then you can edit the link as you like...
Be careful only not to start the editing from the first or the last character of the file name.
You can even edit the DevonThink link if you want to refer to a different page of the same pdf file.


But the best thing is that you can use DevonThink link inside MediaWiki pages and Latex. If you want to learn how read my next post...