Scriptathon

So, at some point over the course of this week … oh … right … just over a week ago, I went through one of my periodic “Mail.app is making me sick to my stomach” kicks.

I can’t even explain why it happens, but it usually starts on those days where Mail is just grinding and grinding and beachballing and gray-timering and I’m getting sick of it. Since most Mac mail apps suck, I usually end up on a primitivist kick, dusting off my old .muttrc and fixing things up a little and going in there to live.

The big problem with mutt (besides deficiencies that may provoke Ed to another fit of profanity (wow! lookit that! That was almost two years ago!) is the same problem running any app on a server far away is … you need to get your stuff to you where you are.

So, as mentioned last week, the first thing I set about solving was the issue of attachment and print handling: both getting attachments and print jobs down from mutt on the distant end, and getting files I want to attach with mutt up to the distant end.

The easiest to solve was attachments up. OS X’s folder actions are very well documented, and it’s trivial to write one in Automator to send any files up to a server when they’re deposited in a given folder.

I was doing it with Transmit, which I own a license for, but I got tired of the GUI clutter of Transmit needing to open a window to do its thing. So I handed the task off to rsync. A folder action is really as simple as:

  on adding folder items to this_folder after receiving these_items



    do shell script "rsync -avz (my attachments folder)  me@remote:/Attachments/"



 end adding folder items to

It happens out of the way and quietly.

Next easiest was getting things down for printing. You can pipe the output of something like muttprint through lpr on your computer, so just setting up a one-use ssh key and making your print_command in mutt something like:

 set print_command="muttprint -p -|ssh foo \"lpr -P {myprinter}\""

handles that.

So I was cruising at that point, but I was troubled by the issue of getting attachments down to my desktop machine. There are surely better ways to do it, but I was hung up on the folder action paradigm, so I ended up finding this little daemon called bubblegum, which I heartily recommend to anyone who needs to do something like primitive folder actions on a server. Bubblegum just puts itself in the background and watches a file, with instructions to fire a script when something happens to that file. The syntax is simple:

 ~/bin/bubblegum -r0 -e syncattach.sh -A ~/Attachments;

The “synattach.sh” script is just a simple rsync job. the “-r0″ argument tells it to do that as many times as it seems Attachments change. Since it’s an rsync job, it’s not particularly expensive to fire that script whenever.

That’s when things sort of ran off the rails. Probably around late Tuesday. I have this several-years-old folder of receipts and registrations sitting on the mail server. Since I’ve been using Mail.app most of the time I’ve had it, it’s been a simple matter to search for a needed registration code or serial number in Mail. But I’m getting all clean and pure on the mail thing, so I need a way to do that in mutt. But mutt, for all its glories, doesn’t really have a useful way to plow through that kind of search, and I’m tired of being chained to mail for keeping that kind of information.

So I set out to work out the perfect serial number storage scheme. It took me through Yojimbo, EagleFiler and finally back to VoodooPad before I cobbled together a combination of folder actions and macros that let me hit “.a” to deposit a message in mutt into a page in VoodooPad. If the message happens to have an X-Label header, that header becomes metadata in the VoodooPad page so when I get around to learning a little lua I can do tag pages and whatnot.

I add the X-Label headers using a clever set of scripts by Alberto Bertogli.

I’m glossing the last few grafs, because the AppleScript involved is inelegant and I don’t feel like showing it. One useful thing about it is that it could easily be ported to something like Mail.app at a future date, when I get off this primitive kick, and tied to Mail Act-On for a handy “file to VoodooPad” keystroke.

So, that’s that. I’ve solved the big nags of mutt in my life and I feel relieved, because all this has been sort of consuming over the past several days.

Here’s a list of things I learned about along the way in less narrative form:

  • muttprint can be told to just output to stdout instead of a printer. Perfect for piping along to lpr somewhere.

  • If you want to trick mutt into doing really interesting things with your messages, Alberto Bertogli’s scripts do it by jimmying mutt’s “print_command” function to get the messages piped out.

  • Bubblegum provides a poor man’s folder actions on unixen besides OS X. Combined with rsync and a folder action on your desktop, you can create a sort of almost-synchronous DAV-like setup. Just make your home folder the master and use “rsync –delete” in conjunction with an “on remove” folder action to make the remote folder reflect deletions and additions on your end.

  • If your script needs a temporary file, “tempfile” can make one to your specifications with a suitably random-ish name, and stick it (with secure permissions) in whatever your default tmp directory is. Great for pushing a mail into a file then operating on it with formail to grab its subject and other info then renaming the tmpfile to something more human-readable.

Two blind alleys I followed in my quest to add an element of metadata to my filing solution involved a pair of handy apps:

  • xattr allows you to add metadata to any file on most Unixoid OSs that have filesystems with extended attributes support (like ext2, ext3, reiserfs, jfs, xfs and Mac’s own HFS+). It’s a pretty freeform tool, which could create problems down the line if you don’t use a disciplined metadata namespace, which …

  • SpotMeta does very well. When you use SpotMeta to tag files, it uses the “org.spotmeta” namespace for them, which imposes as much structure as you need to feel fairly futureproof in that regard. Your tags will exist harmoniously with whatever Apple does with file metadata in the future. It also has some excellent features in the way of creating an interface to file metadata that makes setting attributes simpler and more likely to be standardized. For instance, I can tag a file from one of my authors with a pre-populated dropdown list with their names. No typos to spoil future Spotlight queries.

Two more apps I was glad I found along the way:

  • ManOpen is a GUI manpage reader that even links to things with man pages within each entry. So when you get to the bottom and learn what you really needed was something mentioned in “See Also,” you just click it and there you are. Unfortunately, the developer hasn’t gotten around to building it for Intel machines, but he provided the source as an Xcode project, and it was just a matter of opening the project, going to the “Project” menu, and selecting “Upgrade all targets in project to native.” A rebuild later, and I had ManOpen as an Intel binary. Same process worked for mailtomutt.

  • I got really tired of paging through the terminal for files I was looking at, and Aqualess finally convinced me of the value of the GUI pager. It even has a command line tool if you don’t mind sudden paradigm shifts.

Like I said … I’m feeling kind of relieved. It probably all wouldn’t have taken a week, but Al and I got a batch of discs for season 1 of “The Wire,” so our evenings were consumed.

Tags: , , ,

  • Pingback: Hawk Wings » Blog Archive » Old Style GTD: MailTags for mutt

  • Erik

    Hello, Any chance you’ll move forward with the “file to VoodooPad” script for Mail.app? I would love to have that functionality and am searching all over for it. Thank you, Erik

  • mph

    Hi, Eric,

    You’re just looking for “take the contents of this message and make a voodoopad page out of them, preferably with a CamelCased version of the subject as a title?”

    I’m pretty sure I’ve got a half-completed snippet somewhere I could turn into a working script … enough that you could use it or hack it into shape.

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.