Show a notification banner in OS X

In one of my work project I have bug spam issues. Fake user accounts created by bots and scripts, spammy comments, spammy content, … I built scripts to help me detect spammy patterns, and I run them from my iMac.

The process usually take a while, somewhere between minutes and hours. To see the results, I can wait until it finishes and then process the reports, I can send myself an email every time I detect a spammy pattern. I was looking for a better solution, without having to keep my eyes on the console.

Since I’m using OS X, I thought it would be cool to use the same notification banner used by the Apple email program, and various other software for OS X.

It’s actually just a matter of executing a osascript:

function showNotification($title, $message)
  $message = preg_replace('/[\'"]/', '\"', $message);
  $title = preg_replace('/[\'"]/', '\"', $title);
  exec("osascript -e 'display notification \"$message\" with title \"$title\"'");

Mac OS X Notifications