How can I make org-protocol work on Openbox?

sanjshakun picture sanjshakun · Sep 19, 2011 · Viewed 7.8k times · Source

I tried the instructions - I am using Firefox on Lubuntu (Openbox). But I get the error

"Firefox doesn't know how to open this address, because the protocol (org-protocol) isn't associated with any program".

How should I fix this?

Answer

Mark picture Mark · Oct 5, 2012

The following steps for setting up org-protocol work with Ubuntu 16.04 (Xenial Xerus) and presumably later versions. Org-mode is assumed to have already been set-up (and installed using apt-get install org-mode or via the ELPA repository).

Set-up

  1. Add .desktop file

Create and save a file called org-protocol.desktop to ~/.local/share/applications containing:

[Desktop Entry]
Name=org-protocol
Exec=emacsclient %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;

Then run:

$ update-desktop-database ~/.local/share/applications/

This step makes Firefox aware that "org-protocol" is a valid scheme-handler or protocol (by updating ~/.local/share/applications/mimeinfo.cache), and causes Firefox to prompt for a program to use when opening these kinds of links.

  1. Add config settings to ~/.emacs.d/init.el (or ~/.emacs) file

Have the following settings in your Emacs configuration file:

(server-start)
(require 'org-protocol)

Also add some template definitions to the configuration file, for example:

(setq org-protocol-default-template-key "l")
(setq org-capture-templates
 '(("t" "Todo" entry (file+headline "/path/to/notes.org" "Tasks")
        "* TODO %?\n  %i\n  %a")
   ("l" "Link" entry (file+olp "/path/to/notes.org" "Web Links")
        "* %a\n %?\n %i")
   ("j" "Journal" entry (file+datetree "/path/to/journal.org")
        "* %?\nEntered on %U\n  %i\n  %a")))

Now run Emacs.

  1. Create your notes.org file

Assuming you use the capture templates defined in step 2, you will need to prepare a notes.org file at the location you specified in step 2. You must create this file -- if it is not created along with the headlines specified in step 2, org-mode will just give a warning when you try to capture web-pages. So, given the capture templates from step 2, notes.org should contain the following:

* Tasks
* Web Links
  1. Add bookmarklet(s) to Firefox

Save bookmark to toolbar containing something like the following as the location:

javascript:location.href='org-protocol://capture?template=l&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection())

If you are using an older version of org-mode, you may need to use the following instead:

javascript:location.href='org-protocol://capture://l/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())

Notice the 'l' (lowercase L) in the above URL -- this is what chooses the capture template (automatically) -- it is the key one would normally have to press when capturing with org-mode via C-c c.

When you click on this bookmarklet, Firefox will ask what program to use to handle the "org-protocol" protocol. You can simply choose the default program that appears ("org-protocol").

Using it

(Optionally) select some text on a webpage you're viewing in Firefox. When you click on the bookmarklet, the link and selected text will be placed in the Emacs capture buffer. Go to Emacs, modify the capture buffer as desired, and press C-c C-c to save it.