8

You know, iTerm2 will change the color of the tab to red or purple. But sometime when I run a long job in one tab, I have to check if it's done frequently. So.. can I get notification when there's new output in one tab? If so, how?

  • So the question was about "new output" or about "job done" in the tab? They are different... :/ – hmijail Nov 27 '18 at 9:07
10

You can use Terminal Notifier. Once installed run a command like this:

long-running-command && terminal-notifier -message "Done" -title "Done"

When long-running-command finishes you will get a notification.

  • Note the recommendation of using ; instead of && in nwinkler response – Francesc Rosas Aug 29 '15 at 10:29
  • You can also do long-process && terminal-notifier -message 'Done.' || terminal-notifier -message 'Error running long-process.' for a different message on error. – sleeparrow Jun 14 '16 at 17:01
2

To simplify the usage of the mentioned Terminal Notifier tool, you should create an alias for it, including its parameters, so you don't have to type them all the time.

In your .bashrc file, add an alias like this:

alias termnot='terminal-notifier -message "Done" -title "Done"'

Then you can use it like this:

long-running-command ; termnot

BTW: I recommend using ; to separate the commands instead of &&. && is a conditional operator, it will only execute the second command if the first succeeded. So if your first command failed with a non-zero exit code, you will not receive a notification. Separating them with a semicolon will ensure that the second command is always run, regardless of the first command's exit code. More info here: https://unix.stackexchange.com/questions/100704/difference-between-executing-multiple-commands-with-and

One more thing: To install the Terminal Notifier tool, I recommend Homebrew. Using Homebrew makes the installation as simple as

brew install terminal-notifier

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .