The Grumpy Troll

Ramblings of a grumpy troll.

MacOSX launchd, MacVim, Chrome & EditWithEmacs

One of the biggest productivity enhancements you can make to a browser, when working with web-based services, is to add the ability to edit any text area in a real text editor. Today, I realised that I had not set this up on my work laptop, and my personal laptop is not with me so could not crib the setup. Since I've had to debug this twice, it's time to blog it for next time.

Ironically, Blogger does something weird with the edit box, so I can't use it for composing this post. Grr.

If using Firefox, set up the "It's All Text" extension; that will let you just set the program to invoke. For me, using Google Chrome, it's the EditWithEmacs extension. But Chrome does not let the extension run an arbitrary program. So you need to have a small daemon running as yourself, whenever you're logged in, which can invoke the editor for you.

Find the profile directory, to copy out the pycl.py script:

$ cd "Library/Application Support/Google/Chrome/Default"; \
cd Extensions/ljobjlafonikaiipfkggjbhkghgicgoh/1.11_0/servers
$ ls

Copy that somewhere, make it executable, perhaps strip the quarantine (xattr -d com.apple.quarantine).

Install MacVim. Install the mvim helper too.

Create ~/Library/LaunchAgents/org.grumpy-troll.EditWithEmacs-pycl.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>OnDemand</key>
<false/>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>Label</key>
<string>org.grumpy-troll.EditWithEmacs-pycl</string>
<key>ProgramArguments</key>
<array>
<string>/Users/troll/bin/common/pycl.py</string>
<string>--editor</string>
<string>/Users/troll/bin/common/mvim,--remote-wait-silent</string>
</array>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
</dict>
</plist>

Then run:
$ launchctl load -S aqua org.grumpy-troll.EditWithEmacs-pycl.plist

Of note:
  • pycl.py lets you pass arguments to the editor program, but it splits the editor name string on comma, to supply the multiple arguments
  • use ProgramArguments instead of Program, which does not split on whitespace.
  • Use full paths for the program and the program run from that, as the environ will be rather bare, without $PATH available.

-The Grumpy Troll
Categories: MacOSX vim plist launchd Chrome