10

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
  • 3
    So the question was about "new output" or about "job done" in the tab? They are different... :/
    – hmijail
    Commented Nov 27, 2018 at 9:07

4 Answers 4

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.

4
  • Note the recommendation of using ; instead of && in nwinkler response Commented 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
    Commented Jun 14, 2016 at 17:01
  • Unfortunately, this only allows to track command completion, but not just new output when command is still running. Commented Feb 8, 2022 at 12:47
  • This should not be the accepted answer because it does not answer the question
    – hym3242
    Commented Jun 6 at 8:26
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
2

If you need to get a notification about any output without changing the command, two ways are using Triggers, and changing the profile Notification Center options.

Triggers

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.

Notification Center options

  1. Go to Profiles > select your profile > Terminal
  2. In the Notifications section, enable "Notification Center Alerts" and click "Filter Alerts"
  3. Tick the "Send New Output alert" checkbox iTerm notifications "Filter Alerts" modal
0

The absolute most cross-platform way is to write a transparent text-based terminal emulator(like ssh), that accepts input raw and outputs raw. Then you can program it to send a "BEL" everytime it outputs something.

You must log in to answer this question.

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