iTerm and Growl

by damonp on November 13, 2006

Recent versions of iTerm support Growl notifications. iTerm shows how to initiate Growl events from the command line with:

make; echo $'\e]9;make done\007'

The example shows how to get an alert after a long make. I know I would never remember that command so I wrote a little Bash user defined function to do the same. Add this to your .bashrc file:

growl() { echo -e $'\e]9;'${1}'\007' ; return  ; }

Now the command to initiate a notification would be:

make; growl "make done"

If this snippet is useful to you, please consider buying me a beer.
[paypal-donation]

[ad#Google Links 4]

Popularity: 14% [?]

{ 8 comments… read them below or add one }

David December 30, 2006 at 9:13 pm

Alas, it does not work under GNU Screen

Reply

damonp January 2, 2007 at 2:32 pm

Would it have something to do with the terminal type?

From the manpage:

Each virtual terminal provides the functions of a DEC VT100 terminal

Reply

oudeis January 14, 2007 at 8:58 pm

If you want more control or use a different terminal app, you may want to look at growlnotify:
http://growl.info/documentation/growlnotify.php

Reply

avdempsey August 1, 2007 at 3:17 pm

Works great, good tip. Now, I’m gonna have to figure out how to make growl notifications work for remote jobs.

Reply

Dag Høidahl January 29, 2009 at 4:05 am

If you substitue ${1} with ${*} in the shell function, you don’t need to put the notification text within quotes.

Reply

Evan Krall February 8, 2009 at 5:55 am

You should always quote when you use arguments, unless you have a very good reason not to. Bad things happen otherwise; mostly, newlines and tabs become spaces, globs get expanded, etc. Also, what’s with using echo -e and $’ ‘ at the same time?
Here’s a better way, IMO:

growl() { echo $’\e]9;’”${@}”$’07′ ; return ; }

Reply

Evan Krall February 8, 2009 at 6:54 am

Wow, so I messed that up a little bit.
That should read:

[ccL_bash]growl() { echo $’\e]9;’”${@}”$’07′; }[/ccL_bash]

Also, be careful about the quotes. I’m not sure exactly why, but some of the quotes in my previous post got transformed to forward and backwards quotes, which will mess with things in the shell.

Reply

nobody November 10, 2009 at 4:28 pm

[ccL_bash]growl()
{
if [ "$TERM_PROGRAM" == "iTerm.app" -a "$TERM" != "screen" ]
then
echo -e $’\e]9;’${1}’07′
else
growlnotify -m ${1} “Alert”
fi
}[/ccL_bash]

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: