PER MØLDRUP-DALUM

Quick and Dirty Mac OS X global capturing of notes to org-mode

21. januar 2012

Once bitten by the org-mode bug, every other task management system, time management system, time tracking system, habit tracking system, hierarchical documentation system, list maker, and almost everything else, pales in comparison. I just needed one more thing: a way to capture notes to org-mode from everywhere but Emacs—on Mac OS X. So, here is my very quick and dirty way of making that happen: First you need the org-protocol:

	  (require 'org-protocol)
	
You also need a capture template. I just use the same as when capturing notes from within Emacs:
	  (setq org-capture-templates
	  (quote
	  (("j" "Journal" entry (file+datetree "journal.txt")
	  "* %?%^G\n Entered on %T\n   %i\n"
	  :clock-in t
	  :clock-resume t))))
	
At last you need to have the Emacs server running:
	  (server-start)
	
With the above you can now do this from the command line:
	  emacsclient --no-wait org-protocol:/capture:/j/url/title/body
	
which activates the “j” capture template and don’t wait for Emacs to finish taking the note. Important in the next section. Now create an Applescript:
	  set theURL to "urltest"
	  set theTitle to "theTitle"
	  set theBODY to "theBody"

	  tell application "Emacs"
	  activate (* to brig Emacs in front *)
	  set theScript to "emacsclient --no-wait org-protocol:/capture:/j/" & theURL & "/" & theTitle & "/" & theBODY  
	  do shell script theScript 
	  end tell
	
I’ve put this script in my ~/Library/Scripts folder and use FastScripts to activate it with a key combo: ctrl⌥⌘-n That’s it — for now, until I need extended functionality, like actually using the url, title and body for something.