I like to log in remotely (over ssh) to my machine for quick email checks using pine or mutt, but I usually leave Mail.app running when leaving home.
The problem is that with both mail programs running at once, they would compete for the IMAP connection and complain. So, I wanted a simple way to quickly & gracefully quit Mail.app remotely. I know I could use killall Mail, but I wanted something that would save any mail being composed and such, so ApplesSript was the answer.
I ended up adding the following two lines to my .profile (I like .profile for config better than .bash_login because it seems to get used by X11 and Terminal.app). It's just a simple inline Applescript:
# make it easy to remotely quit Mail.app
alias quitmail='osascript -e "quit application "Mail" saving yes"'
Please enter any better ideas in the comments ... I'm open to better approaches!
Mac OS X Hints
http://hints.macworld.com/article.php?story=20040611103530635