Command-line mail on OS X: re-alpine and Geektool
I manage my remote web site through command-line tools that transfer logs, run log analyses, and upload from the Django CMS. These automated processes generate a lot of mail to the mail file in /var/mail.
I don’t want to set up a forward file, because that sets up a dependency that might mean I don’t receive messages telling me that something’s wrong, because something’s wrong! Mac OS X Mail used to be able to set up a /var/mail account, but it can’t do that any more. And because OS X has such great GUI tools, I sometimes find that I don’t enter Terminal for days at a time.
A better mail client
The built-in Unix “mail” command is about as basic as you can get and still be able to actually read your mail. Over time, I’ve found it necessary to come up with tricks to make it easier to navigate, such as reading all of my mail in reverse order, counting down. Today, I decided it was time to install something else.
I was a big fan of elm over pine back in the day, so the first one I tried was mutt. I was able to ./configure and make the mutt 1.5.20 source code and then open ./mutt to view my /var/mail messages. It wasn’t immediately obvious what to do next, however. It didn’t support the up and down arrows on my keyboard out-of-the-box and the choice of colors was hideous. So before mucking around with the configuration files, I thought I’d find out how Pine was doing.
Pine’s gone through a few incarnations, from pine to alpine and now to re-alpine. Getting re-alpine working on OS X is even easier than mutt. It comes as a .dmg file, and all you have to do is drop color-coded files into one of two directories. That’s it: it is then installed and ready to use from the command-line. The command is still “alpine”, as is all of the branding inside.
The re-alpine interface is nearly the same as the old pine interface, and is very easy to use for a command-line app. Type “alpine” and it will bring up the opening screen; from there, type the ‘I’ key to go to the message index; the default “folder” is your /var/mail inbox.
The available commands are listed on the bottom of the screen.
When you have mail waiting in your /var/mail inbox on Mac OS X, opening up a terminal will tell you that you have mail, and whenever any command completes, it will tell you that you have mail.1
But with better and better GUI tools, it’s become less and less necessary to go to the terminal. So some form of notification becomes useful. I suppose, someday, I’ll have to install Growl. Growl looks great, but it requires writing scripts to take advantage of it. I prefer things (like SilverService) that let me just use existing scripts.
While looking for remote monitoring tools at the office this week, I ran across GeekTool. GeekTool is like SilverService for notifications. All it does is display something on the desktop. At the office I’ve quickly started using it to monitor log files and remote graphs. But the shell output option is perfect for displaying incoming mails.
- /usr/bin/mail -H
This is just the command-line mail program with the option to display the index of waiting mails and immediately quit. If there are messages waiting, it will display the message date and subject, and if not it will display nothing.2
So this will leave the desktop alone, unless there is mail waiting to be read from one of my cron jobs.
GeekTool is pretty cool, and you can download a bunch of pre-made “geeklets” for it (I haven’t used any of them). You can place them on the desktop and arrange them as you see fit.
I believe that this is actually the “bash” shell that is checking the inbox to see if it needs to warn you that you’ve got mail.↑
Mail actually sends a notice to stderr, but Geektool takes its input from stdin so it doesn’t see that.↑