Sidebar

Applescript for opening an email from exmh within Apples' Mail.app

The purpose of this applescript is to open an email message from the EXMH email program with the Apple Mail.app software. This script accepts the path to an email message as argument. It expects this to be a message from mh/nmh/exmh and will write it into a temporary mailbox directory, move it to the Mail.app folder "exmh" and open it. I stole a whole lot of code from the Burst digest messages.scpt - Version 1.1 script. So tons of credit should go to Andreas Amann, who gave me permission to use bits of his code, and Andy Fragen. This is my first applescript and mainly a hack for my personal purposes, so expect data loss, harddisk formatting and other such side effects.

You might also want to add a button to exmh to be able to open a message in Mail.app by the click of a button. I use the following modification of ~/.exmh/exmh-defaults for this purpose:

*Mops.ubuttonlist: applemail
*Mops.applemail.text: Mail
*Mops.applemail.command: exec /usr/bin/osascript /opt/bin/OpenExmhMessageWithAppleMail.scpt [glob ~]/Mail/$exmh(folder)/[Ftoc_CurMsgs]

You can download the script source code here; the compiled binary is here.

gdirs for the bash shell

If you spend most of your day on the command line, you will know how often one has to change directories. Keeping track of all the recently visited locations can be a nightmare. The good news is that gdirs exists! The bad news is that it's zsh-centric. I have slightly tweaked one of the scripts written by William G. Scott to work under the bash shell (and probably under any other shell with little adaptation). First you need the modified _guidirs script. Put it in a location in your path. Then you should add the following to one of your bash startup files (I use an .alias file for this).

### gdirs
# keep the ~/.gdirs.dirstack file from growing too long (250 entries seems ok)
tmp_timestamp=$(date | awk '{print $4}')
command touch ~/.gdirs.dirstack
command cat ~/.gdirs.dirstack|awk "{if(d[\$0]++==0)l[++c]=\$0}END{for(i=1;i<=c;i++)print l[i]}" >  /tmp/$tmp_timestamp.gdirs.dirstack
command tail -250 /tmp/$tmp_timestamp.gdirs.dirstack >| ~/.gdirs.dirstack
command rm -f /tmp/$tmp_timestamp.gdirs.dirstack
function gdirs() { builtin cd `_guidirs $*` ; }
function cd_gdirs() { builtin cd $* ; echo $PWD | perl -pi -e 's/ /_SPACE_/g'  >> ~/.gdirs.dirstack ; }
alias cd='cd_gdirs'

Please be very careful and test this first, before adopting it systematically. It can have very nasty side-effects, should you end up with a non-functional cd command. I have also noticed that I did get different behavior on two different machines (which made me add the builtin to the definitions.

The actual raw directory stack is maintained in ~/.gdirs.dirstack. Use gdirs as described here (without any option, with -f or -F). It will open a selection box with the recently visited directories, starting in reverse chronological order.

And here's the obligatory screenshot:

Image 2