The document describes the settings to use org-protocol
and is based on this article.
The settings were tested on Emacs 25.1 on ArchLinux and Windows with Firefox 47.
- Create bookmark with the following as location:
javascript:(function()%20{location.href='org-protocol://capture://w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection());})()
- Add the following code to
init.el
:
(use-package org-protocol
:defer t
:config
(setq org-capture-templates
(quote (("w" "Weblink" entry (file (expand-file-name "bookmarks.org" "~/org/"))
"* %c\n :PROPERTIES:\n :CREATED: %U\n :END:\n - Quote:\n %i" :unnarrowed)))))
Notes:
- If you don’t have
use-package
, just copy thesetq
part - Both
org
andorg-protocol
have deferred loading, hence we’ll addrequire
for the latter in next sections, when the former will be loaded by the protocol itself - The letter “w” both in the bookmark and in the template may be changed, but it should be the same for both cases
- After completing the instructions, restart Firefox, click on the bookmark once & approve the usage of the handler. Later you may check that
org-protocol
has an associated handler inabout:preferences#applications
- Create
~/.local/share/applications/org-protocol.desktop
with the following content:
[Desktop Entry]
Name=org-protocol
Exec=sh -c "emacsclient -e \"(require 'org-protocol)\" && emacsclient -c %u"
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
- Run in the terminal
update-desktop-database ~/.local/share/applications/
- If needed, download
nircmd
utility from NirSoft to run batch files without visible console window; otherwise, change the configuration accordingly - Create
runOrgProtocol.bat
in some directory, remove or replace-f %HOME%\.emacs.d\volatile\server
:
@echo off
emacsclientw.exe -a "" -f "%HOME%\.emacs.d\volatile\server" -e "(require 'org-protocol)"
emacsclientw.exe -a "" -f "%HOME%\.emacs.d\volatile\server" %*
- Create file with
bat
extension, run it as administrator, replacing%HOME%\Scripts\runOrgProtocol.bat
accordingly:
@echo off
reg add "HKEY_CLASSES_ROOT\org-protocol" /t REG_SZ /d "URL:Org Protocol" /f
reg add "HKEY_CLASSES_ROOT\org-protocol" /t REG_SZ /v "URL Protocol" /d "" /f
reg add "HKEY_CLASSES_ROOT\org-protocol\shell\open\command" /t REG_EXPAND_SZ /d "c:\progs\nirsoft\nircmd.exe execmd %HOME%\Scripts\runOrgProtocol.bat \"%%1\"" /f