Native OSX notifications from iTerm with Triggers

As an addition to the last Show notification when PHPUnit tests are done in iTerm article there is also a solution to fire notifications from iTerm on certain triggers with native OSX notifications (instead of Growl).

To do this just install the terminal-notifier gem with[1]:

gem install terminal-notifier

Then create a file called iterm-notify in your /usr/bin/ folder with the following content:

#!/usr/bin/ruby

require 'rubygems'
require 'terminal-notifier'

message = ARGV[0] || "Task completed"
title = ARGV[1] || "iTerm"
activate = 'com.googlecode.iterm2'
sender = 'com.googlecode.iterm2'

TerminalNotifier.notify(message, :title => title, :activate => activate, :sender => sender)

Make it executable with

$ sudo chmod +x /usr/bin/iterm-notify

You can now create a Trigger[2] with the Action Run Command... and the Parameters iterm-notify "Tests successful" "PHPUnit". Both parameters are optional. The first is the message and defaults to "Task completed" and the second is the title which defaults to "iTerm".

The result will look like this:

iTerm notification

You will be brought back to iTerm when you click on the notification. iTerm will now show up in your notification center settings and you can also make the notifications sticky there.

There is also a solution to add images to notifications.


  1. Prerequisite: You need to have ruby installed ↩︎

  2. You find them under Settings => Profiles => Advanced => Triggers ↩︎