Read the rest of the article for the script and installation instructions.
I'm really not a scripting king, but here it is. For installation you don't need to know much about the command-shell and I'll describe all editing-tasks.
First, create the following script in your preferred UNIX text editor:
#!/bin/shEdit the file with the following steps:
# check if there's a network connection; mailchecking doesn't make
# much sense without network connection
ok=`/sbin/ping -c 1 -q 17.254.0.91 | /usr/bin/grep -c 100%` ; ko=0
if test $ok = $ko; then
# check if Mail.app is already running; we needn't check mail
# nor do we need to start Mail.app in that case
ok=`/bin/ps -aux | /usr/bin/grep Mail.app | /usr/bin/grep -vc grep` ; ko=0
if test $ok = $ko; then
# check if there's new mail; if there is: start Mail.app
ok=`/usr/bin/fetchmail -c | /usr/bin/grep -c message` ; ko=0
if test $ok = $ko; then
exit
else # !!adapt the path and the mail-client in the following line!!
/Applications/Mail.app/Contents/MacOS/Mail &
fi
fi
fi
- [optional] change the ip-adress (17.254.0.91 is apple.com's) to an adress of a 'close' server.
- [if you're not using Mail.app] change every occurence of "Mail.app" to the mail-client you're using.
- [if your mail-client doesn't reside in /Applications/] adapt the path of the mail-client
Next, configure the fetchmail program so it knows about your mail servers. Save the following text to a file named ".fetchmailrc" in your home directory:
server your.popserver.name # Change to your mail servernameNOTE: The space at the beginning of all lines after the first is important! Change the file permissions on .fetchmailrc in the Terminal with chmod 0710 .fetchmailrc, and set the owner of the script to root with sudo chown root .fetchmailrc.
protocol POP3 # Change to your mail protocol
username MAILUSER # Change MAILUSER to your user's mailserver name
password MAILPWORD # Set MAILPWORD to the corresponding password
fetchall
keep
noflush
mda "/usr/libexec/mail.local USER" # Change USER to your OS X username
[Editor's insert: I couldn't get the script to work when it was owned by root, but I was running it in my user shell, not as a cron job. I believe root ownership is required if you take the next step and add the script to cron.]
Add the following crontab-entry:
*/1 * * * * USER sh /Users/USER/bin/MailCheck.shHere you have to change "USER" to your (tada!) OS X user name, and adapt the path to reflect the location where you saved MailCheck.sh. If want to have mails checked just every five minutes, change "*/1" to "*/5". If you're not familiar with cron, try CronniX, an OS X gui for cron.
That's it. After restarting cron or rebooting, the mailchecker should work (at leat it works for me). The script takes almost no system-load or memory. I guess that the script can be improved a lot. Hints are welcome.

