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?
4 Answers
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 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. 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– hym3242Commented Jun 6 at 8:26
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
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...
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
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.