How do I make iTerm terminal notify me when a job/process is complete?
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
.
Related videos on Youtube
truth1ness
Updated on October 14, 2020Comments
-
truth1ness over 3 years
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).
-
truth1ness about 9 yearsSo am I correct that there is no global way to get an alert for any finished process because I need to have run the script once to know what it writes at the end of the process (and I have to create one for every script I run)? For example, the last line for a youtube-dl process is
[download] 100% of 40.13MiB in 00:13
but this line is repeated for every file it finishes. What would I put in for my 'end-of-my-process' string? Could I make a trigger for when my default shell prompt~ >
shows up again? -
baf about 9 years@truth1ness I don't think there is a generic way to be informed about finished process.
iTerm
sends notifications for new terminal output, for end of terminal output. This can work for some processes. The way to work for all processes is what I suggested. "end-of-my-process" message can be any unique string. Unique it such way that it will not be printed by your process. Could be literally "end-of-my-process" text. You must enter exactly same string in the trigger definition and attach a notification to it. I don't know if it will work with shell prompt. You must try it yourself. -
truth1ness about 9 yearsHmm, with this command
osascript -e 'display notification "Task finished" with title "Terminal"'
I seem to be getting this error2015-05-04 12:34:23.227 osascript[30467:1130887] Error loading /Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools: dlopen(/Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools, 262): no suitable image found. Did find:
-
truth1ness about 9 yearspart two of error
/Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools: no matching architecture in universal wrapper osascript: OpenScripting.framework - scripting addition "/Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax" declares no loadable handlers.
-
truth1ness about 9 yearsAh, I misunderstood, I got it now. I was able to get an alert to pop up with the echo output "end-of-my-process". However, I also get an alert when I actually issue the echo command before the process starts. How would I tell iTerm to ignore the string when I actually issue the command and only look at the echo'd string? From the help file I tried prepending the trigger regex with \0 ("The entire value matched by the regular expression.") but it still executes the trigger twice.
-
Mark Setchell about 9 yearsAre you on a system older than Mavericks or Yosemite?
-
baf about 9 years@truth1ness Be creative, for example use
echo "end-of-""my-process"
with quotes inside. It will match "end-of-my-process" text only when process finished. -
truth1ness about 9 yearsNope, Yosemite 10.10.3
-
Mark Setchell about 9 yearsOh, that's odd. Can you try something simpler like
osascript -e 'display notification "Hello"'
- by specifically copying and pasting from here. -
truth1ness about 9 yearsResult: (testenv3)testenv3 > osascript -e 'display notification "Hello"' 2015-05-04 19:56:53.205 osascript[57251:2660824] Error loading /Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools: dlopen(/Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools, 262): no suitable image found. Did find: /Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax/Contents/MacOS/List & Record Tools: no matching architecture in universal wrapper
-
truth1ness about 9 yearspart two: osascript: OpenScripting.framework - scripting addition "/Users/mmarotta/Library/ScriptingAdditions/List & Record Tools.osax" declares no loadable handlers.
-
lacostenycoder over 7 yearsstackoverflow.com/users/2836621/mark-setchell this is great!! Is there a way to not open apple script editor when I click on the notification by accident?
-
Charles L. over 6 yearsAfter installing shell integrations you might want to go to iTerm2 -> Preferences -> Profiles -> Terminal , scroll down & uncheck "Show mark indicators", I did not like this shell integration. You might also want to Edit -> Marks and Annotations -> Alerts -> Post notification if you want the os notifications instead of an alert style popup.
-
phirschybar over 5 years@simonhamp I suggest using triggers (iterm2.com/documentation-triggers.html) for buried sessions
-
Lucas over 5 years@dwanderson Did you ever get this working with tmux? This would be so helpful
-
Ben Blank over 4 years
tput bel
is great because it also works when connected to another machine via e.g. ssh. -
Rich Steinmetz over 4 years@Lucas there is a line in the docs that says that shell integration doesn't work with tmux or screen iterm2.com/documentation-shell-integration.html
-
Rich Steinmetz over 4 yearsto chain osascript notification and beep:
alias notify="osascript -e 'display notification \"execution finished\"'; osascript -e 'beep 5'"
-
WTIFS about 4 yearsThis eye scares me!! (╯‵□′)╯︵┻━┻
-
Shamal Karunarathne over 3 yearsThe alert does not work on ssh sessions for me. Anyone experience the same?
-
GregL over 3 years@ShamalKarunarathne Have you installed the shell integration scripts in the machines you are SSHing to?
-
Shamal Karunarathne over 3 years@GregL Thank you it worked. Didn't know I had to install the integration in SSH hosts as well.
-
maulik13 about 3 yearsOMG not only this is helpful, but so cool and a very straightforward way to do it.
-
Kyr about 3 yearsThis answer is not receiving enough votes given its awesomeness. 🤯
-
om-ha almost 3 yearsTHIS IS SIMPLE YET AMAZING!
-
Kostas Demiris about 2 yearsThis is super awesome! How didnt I know it ???