Skip to main content

Capturing text from any Mac Application into Emacs org-mode with Automator and org-protocol

After decades of using vi and Vim I switched to Spacemacs which is an amazing vi keystroke emulation layer running on Emacs and configured with an amazing set of preconfigured layers for different tasks. I decided to give it a try after seeing Org-Mode in action and seeing it was a nice taking system with integrations with almost anything imaginable. A few weeks ago I found out about org-protocol and followed this post by Jethro on using a bookmarket to capture from the Web to Emacs. 

This page assumes a few things

  • You use Emacs on a Mac
  • You are using org and understand how to use capture and capture templates.
  • You need to yank text from random apps into Emacs
You don't need to be using Spacemacs and this should work with any install of Emacs that supports org, org-capture and org-protocol.

Creating Automator Action

Start Automator. It's this icon. I'm guessing many people have had this for years and have never used it. 

Open it and pick Quick Action

Grab the following text:

data="$@"
encoded=$(python -c "import sys, urllib; print urllib.quote(' '.join(sys.argv[1:]), safe='')" "${data[@]}")
emacsclient "org-protocol://capture?template=g&body=$encoded"

 I borrowed some of it from this stack overflow question.

You want to head over to "Utilities" and drag over the "Run Shell Script" block. It should look like this:

Save it. You can confirm by checking the installed extensions in System Preferences. I named my test copy "test foo" and then created AddToEmacs as the permanent name.

Verify Action


Configure Emacs

In Emacs, open your init file. If you aren't using org-protocol, you'll need to install it with M-x package-install and add this:

(require 'org-protocol )

Add this to your org-capture-templates section. I am using g for "Grab"

("g" "Grab" entry (file+headline "~/Documents/inbox.org" "Grab" )
"* %? \n%i\n" :prepend t :created t )

Capturing Text

Highlight text, right click and pick "Services" and then what ever you named it. I called it "test foo". 



Emacs will open in the background with the text sitting in the capture frame.

You should see something like this:



Comments

Popular posts from this blog

Halloween Candy Distribution Robot Chute

I am not a hardware guy and my Brooklyn apartment lacks true workshop space but we were able to put together a reasonably well done candy chute robot able to deliver candy directly into Trick-or-Treat's candy bags.  My wife wanted the robot to blink lights and wave an arm. I decided to use a servo motor driven by a Raspberry pi pico running MicroPython. The pico and MicroPython were chosen because I had them already from prior projects with my son.  Legos, chopsticks and leftover screws. Only the best. Cardboard, aluminum foil and Tupperware to protect the electronics. Those are the bags of candy and we managed to go through all of the candy by dark. This is what it looked like up on our balcony. How do you get the candy down to the trick-or-treaters? A dryer duct. Last time we used plastic sheeting and zip ties. The $25 to get a duct was worth it. We tested it with fun sized chocolate, smarties, double bubble gum, skittles and m&ms. The bagged candy, skittles and M...

I can't vote for that, no can do

Mastodon