Skip to content

Instantly share code, notes, and snippets.

@Glutexo
Created February 17, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glutexo/ac26f37058e32037cb41 to your computer and use it in GitHub Desktop.
Save Glutexo/ac26f37058e32037cb41 to your computer and use it in GitHub Desktop.
Log mail an raise an OS X notification
#!/bin/sh
# Mail logging combined with OS X notification.
# Uses terminal-notifier – https://github.com/alloy/terminal-notifier.
# Writes the whole message with header to the file, timestamp included,
# and raises a system notification with the message subject. The log
# file (LOG_FILE variable) is opened in the Console app upon clicking
# on the notification.
#
# To use with PHP instead of sendmail, alter php.ini like this:
# sendmail_path = /Users/…/…/mail-log-and-notify.sh
LOG_FILE=/Library/Logs/php-sendmail.log
EXECUTE_COMMAND="open /Applications/Utilities/Console.app $LOG_FILE"
TITLE="PHP mail"
NO_SUBJECT="(no subject)"
date >> "$LOG_FILE"
while read LINE
do
echo "$LINE" >> "$LOG_FILE"
SUBJECT_LINE=`echo "$LINE" | grep "^Subject: .*\$"`
if test "$SUBJECT_LINE"
then
SUBJECT=`echo "$SUBJECT_LINE" | sed "s/^Subject: //"`
fi
done
echo ".\n" >> "$LOG_FILE"
if test -z "$SUBJECT"
then
SUBJECT="$NO_SUBJECT"
fi
terminal-notifier -title "$TITLE" -message "$SUBJECT" -execute "$EXECUTE_COMMAND"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment