Can I get mac notification when a Tab has new output in iTerm2?

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?


Solution 1:

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.

Solution 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