Org-Capture Links via Org-Protocol from Firefox


Introduction

After reading Org-mode Workflow Part 1: Capturing in the Inbox - Jethro Kuan, I had to try it out. Below is my current setup for OSX using Firefox to send webpage link to my inbox.org file.

Emacs deamon

Create the daemon application

Open the Script Editor and paste the following:

tell application "Terminal"
do shell script "/usr/local/bin/emacs --daemon"
endtell

Note: Run `which emacs` to find the path of your emacs, mine is /usr/local/bin/emacs.

Save this as an Application called "Emacs Daemon" in your Applications folder

Add as a login item

Goto System Preferences > Accounts

  • With your user name selected, click on the Login Items tab
  • Click on the plus sign
  • Browse to your applications folder and find "Emacs Daemon"
  • Don't worry about the "hide" checkbox, since it the dock icon disappears naturally

Run the script now to start the Emacs Daemon unless you want to relogin.

Emacs client

brew cask install emacsclient

Org-Capture Firefox Extension

Emacs config

Add this to your emacs config:

(require 'org-protocol)

;; Kill the frame if one was created for the capture
(defvar kk/delete-frame-after-capture 0 "Whether to delete the last frame after the current capture")

(defun kk/delete-frame-if-neccessary (&rest r)
  (cond
   ((= kk/delete-frame-after-capture 0) nil)
   (t
    (print "kk/delete-frame-after-capture")
    (setq kk/delete-frame-after-capture 0)
    (delete-frame))))

(advice-add 'org-capture-finalize :after 'kk/delete-frame-if-neccessary)
(advice-add 'org-capture-kill :after 'kk/delete-frame-if-neccessary)
(advice-add 'org-capture-refile :after 'kk/delete-frame-if-neccessary)

(custom-set-variables
 '(org-capture-templates
   '(
     ("L" "Protocol Link" entry (file+headline "/PATH/to/your/inbox.org" "Inbox")
      "** [[%:link][%:description]] %(progn (setq kk/delete-frame-after-capture 2) \"\")"))))
;; :immediate-finish t