Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

(OSX Specific)

I, like many others besides myself often find myself kicking off a process in the shell that takes a minute or two to complete (a large svn commit for example). During that time, I often alt-tab and refresh reddit/slashdot/wikipedia/whatever. It would be great to have something set up that posts a growl notification when the shell process is over.

In my ideal world, it would work like this: "If a process just exited from a tab open in Terminal, post a growl notification."

Anyone else have something like this set up?

share|improve this question
    
Note that growl will only notify you if you are still sitting at the screen. For longer programs, use the "say" command to get an audio hint that it is finished. –  user31752 Nov 2 '10 at 19:55
    
@mankoff: You can configure the growlnotify application notification settings in Growl.prefPane to include an audio notification sound. It's not, however, changeable depending on the command you execute, like say would be. But it's way less creepy. –  Daniel Beck Nov 2 '10 at 20:04
add comment

6 Answers

You can install growlnotify to do this.

$ ./some_program && growlnotify Title -m Message

Of course you would need to think of this before performing your command. The alternative (I don't know how to achieve this though) would be a Growl notification for every single command, which would be insanely annoying.


To simplify use of growlnotify for your use case, edit ~/bash_profile and add the following:

function long {
    $@
    /usr/local/bin/growlnotify Finished -m 'Done'
}

now you can simply long your_command (similar to sudo). Ctrl-A positions the cursor at the beginning of the line, if you (like me) always type the actual command first and need to add the prefix afterwards.

My bash-fu is unfortunately insufficient to be able to add the command to the growlnotify message


per @mankoff's comment to this answer:

You can simply type while the command is running, it gets executed afterwards. I created the following function for me:

function gn {
    /usr/local/bin/growlnotify Finished -m "$@"
}

Use as gn svn.

share|improve this answer
2  
You don't need to think of it before the command. If, while it is running, you realize you want to be notified when it is done, just type "gn foo" (or "say done", for audio hints), press enter, and that command will run when the current one finishes. –  user31752 Nov 2 '10 at 19:54
    
Re you comment on doing this automagically... Use PS1 or something to touch a timestamp. Use PS2 to verify how long since PS1 touched it. If it has been > n seconds, then run growlnotify. Now it isn't annoying because it doesn't happen for every command. –  user31752 Nov 2 '10 at 19:56
    
@mankoff True. So a simple function to reduce the typing is sufficient. –  Daniel Beck Nov 2 '10 at 19:57
    
@mankoff PS2? Isn't this just the continuation prompt? It doesn't prefix every output line..? –  Daniel Beck Nov 2 '10 at 20:02
    
The PS1/PS2 were just guesses as places I'd start looking if I wanted to implement this. Perhaps the whole thing can be embedded in just PS1. And perhaps there are entirely different ways to make a generic growl-for-every-command setup. –  user31752 Nov 2 '10 at 21:17
show 5 more comments

What you need is growlnotify which is a CLI program to trigger growl notifications. You could use it as:

./script.sh;; growlnotify -m "done"

It has a few more knobs you can play with, use growlnotify -h for more info

share|improve this answer
    
Thanks. I just commented at the same time when I found that too. Semicolon makes more sense than the && as well. –  ezrock Nov 2 '10 at 19:01
1  
@ezrock I figure one could use && and || to have different messages between success and failure states, but if one's only interested in a message being shown after the command executes, then ;; is foolproof. =) –  xorbyte Nov 2 '10 at 19:40
add comment

Modifiying Daniel Beck's answer if you do this slight change it makes it very nice.

function long {
    command=$@
    $command
    /usr/local/bin/growlnotify Finished -m "$command completed."
}

Then when you run 'long svn up' you will see message 'svn up completed.'

Very nice if you run many time consuming shell scripts at the same time.

share|improve this answer
add comment

Use growlnotify.

ls && growlnotify -H localhost -m "message"
share|improve this answer
add comment

I just poked around some more and found a simple method for this. It's a little more manual than I would like it to be, but here goes.

  1. Install growlnotify (It's in the extras folder of Growl's installation download)1.
  2. Append <&& growlnotify -m "Message"> to a long process.

That works for me right now, but I could do better, methinks.

share|improve this answer
add comment

This is a way to have it invoked automatically for "long running" processes: http://hints.macworld.com/article.php?story=20071009124425468

It hooks into the $PROMPT_COMMAND and notifies completion of processes taking longer than 10 seconds to complete. You may need to tweak it to suit your own environment and workflow (for example, ignoring completion of less or editor invocation), but it seems to work reasonably well out of the box.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.