I need a way to trigger a Growl notification when a Beep is triggered in the Terminal.

Ideally, I 'd love to have a way to capture the terminal output - from an SSH server let's say - and handle it using Growl - conditionally.

Any ideas?


Solution 1:

An interesting question, but fairly open-ended. What sorts of beeps are you trying to capture? And what output are you trying to handle? Errors? Completion of processes?

growlnotify is the command-line tool to post Growl notifications. It has to be installed separately, and can be found in the Extras folder on the Growl disk image.

You could use the unix trap command to trap any errors in a script and send output to growl using growlnotify. I'm not aware of any way to trap the terminal bell, you have to trap for some specific unix signal.

To see what signals are available on your system, type kill -l into the terminal. The above-linked article on the unix trap command has a list of common trap signals.

If you're looking for a way to notify with growl the completetion of a long-running terminal script, here's a solution on Mac OS X Hints.

If you just want to redirect all terminal output to growl, the technique on Mac OS X Hints could be modified for this. Put this in your .profile, .bashrc or .zshrc. It will redirect your command output to growl.

# Before a command execution
preexec() {
   export PREEXEC_CMD="Command: $1"
   $1 | growlnotify -n "Terminal" ${PREEXEC_CMD:-Some command}
}

I'll leave it as an exercise to the reader to add logic to redirect conditionally depending on command or whatever parameters, as I'm unaware as to what "conditions" you're looking for. :)

Solution 2:

What you want is possible, but I don't think the tool exists yet. As a place to start developing it yourself, check out BounceTerm (comes with source) which turns beeps and bells into dock bounces. Seems to be the exact behavior you seek but with a slightly different output.