Registering Org-Protocol with XDG

2012/07/04

Org-protocol is a cool way of exchanging information from external applications and Org-Mode. In the past I have used some ugly hacks to get org-protocol working on Linux. However I have now found a clean way of getting xdg-open (a tool for configuring default applications in Linux) to open org-protocol links and pass them to emacs. On Archlinux all I had to do was create the file /usr/share/applications/emacsclient.desktop with the following:


[Desktop Entry] 
Name=Emacs Client
Exec=emacsclient %u 
Icon=emacs-icon 
Type=Application 
Terminal=false
MimeType=x-scheme-handler/org-protocol; 

This is handy because now I can get Google Chrome/Chromium to open org-protocol and pass links to emacs. In order to do this I have a bookmarklet with the following as the bookmark:


javascript:location.href='org-protocol://store-link://'+encodeURIComponent(location.href)+\
'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())

Now when I click this bookmarklet it executes emacsclient and org-store-link to make the webpage link available in Emacs. To paste the link use org-insert-link