12

(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?

ezrock
  • 523

8 Answers8

11

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.

Daniel Beck
  • 111,893
2

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

roguesys
  • 3,110
2

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.

bmucklow
  • 121
2

Now that OSX 10.8 and later has native notifications, this is how I accomplish the same goal via terminal-notifier:

  1. Install brew
  2. $ brew install terminal-notifier
  3. Add this to ~/.bash_profile:

    function gn {
        terminal-notifier  -message ' ' -title 'Finished'
    }
    

Make sure that you have sourced your profile with . ~/.bash_profile (not necessary for future terminal sessions), since your profile is sourced automatically when creating a session.

Test with your favorite command, followed by the function call.

ls ; gn

The arguments to terminal-notifier can stand some improving, but a quick attempt of grabbing the previous command to pass to the function wasn't successful and this gets me all of the functionality that I need. Namely, adding ;gn to get a notification at the end of any long-running process.

TTM
  • 239
ezrock
  • 523
1

Use growlnotify.

ls && growlnotify -H localhost -m "message"
fideli
  • 14,884
1

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.

0

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.

ezrock
  • 523
0

OSX 10.9+ solution with no third-party software:

In OSX 10.9 and above, you can use the AppleScript command display notification to display a growl from the terminal like so:

osascript -e 'display notification with title "Process Completed."'

If you don't want to type all that every time, you can use an alias:

alias growl='osascript -e "display notification with title \"Process Completed.\""'

Example:

long-running-script.sh; growl