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?

1
  • 1
    So the question was about "new output" or about "job done" in the tab? They are different... :/ Nov 27, 2018 at 9:07

3 Answers 3

11

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.

3
  • Note the recommendation of using ; instead of && in nwinkler response Aug 29, 2015 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, 2016 at 17:01
  • Unfortunately, this only allows to track command completion, but not just new output when command is still running. Feb 8 at 12:47
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
0

If you need to get a notification about any output the triggers may be used.

Go to Session > Triggers > Add Trigger...

iTerm2 Add Trigger dialog

Then enter .* (meaning anything) in Regular Expression box and choose Post Notification... in the Action dropdown. Enter the message you would like to see and press OK.

Now every time the new output appears in the console the notification in the Notifications center will be shown.

Later you can disable/reenable the trigger using Session > Triggers menu.

You must log in to answer this question.

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