How do I make iTerm terminal notify me when a job/process is complete?
A notification center notification would be ideal but growl, bounce dock, sound, etc would be fine, too (or if this can only be done in Terminal.app I'd be willing to switch back). Is there an option somewhere in iTerm to turn on notifications or is it something I'm supposed to type at the end of a command in the terminal? If the latter, is it possible to add an alert once process has started (for example if I realize it's going to take longer than I initially expected, I'm bad at guessing).
Solution 1:
Notify on already running processes:
Shortcut: ⌥⌘ A or:
Edit -> Marks and Annotations -> Alerts -> Alert on next mark
: iTerm
will literally keep an eye (on the top right corner) of your terminal. Once the command is finished, it will contact the Notification Center
.
Why?
Command was already launched, completion time was underestimated, and we don't want to cancel the command or wait for its completion.
(i.e., brew update
after a long time)
Requirements
iTerm: Shell Integration:
iTerm2 -> Install Shell Integration
Note that the integration will not show notifications until iTerm2 is restarted.
Solution 2:
And you can always use the say
command.
Usually when you are running a long process inside the terminal and want to get updated you can simply use this command to speak out things like done
or error
or bazinga
.
mvn clean install; say done
This command builds a java spring app, and takes a long long time, and it will speak out done
after the process is complete.
Solution 3:
You can add any one of the following after any command, with a semi-colon in between the command and it:
afplay /System/Library/Sounds/Ping.aiff -v 2
osascript -e 'beep 3'
tput bel
or, if you like Notification Centre
osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
You can also make an alias in your profile, called notify
and add that at the end of your command. So, in your login profile
alias notify="tput bel"
then
sleep 10; notify
Or, if you started your command and it is "hanging", just type notify
and hit Enter
and it will run your notify
alias at the end, whne the command has finished, e.g.
sleep 20
# wait 5 seconds before realising this will take 20 seconds
notify<Enter>
Solution 4:
iTerm2
supports Growl
notifications. You can turn it on in each profile settings.
Select a profile in Preferences…
->Profiles
.
Then in Terminal
tab there is an option Enable Growl Notifications
.
Remember to also enable iTerm
notifications in Growl
preferences.
If you want to get notification for a given process you could try to experiment with Triggers
. You define triggers in Advanced
tab in a profile settings. In this way you may assign a Growl notification to a particular output of your process (regexp).
You could for example do:
$ mycommand; echo "end-of-my-process"
And connect trigger to "end-of-my-process" message.
Update
Read more about triggers on iTerm2.com.
Solution 5:
There is an OSS tool called noti.
You can easily install it with brew install noti
and start using it just by prefixing your command with noti
like noti sleep 3
.