truth1ness
truth1ness

Reputation: 5041

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).

Upvotes: 192

Views: 55930

Answers (8)

tkolleh
tkolleh

Reputation: 423

If using MacOS there is the excellent Alerter project that lets you interact with commands you've alerted on. e.g.

gh pr checks --watch
local response=$(alerter -title "PR Checks" -subtitle "$basename" -message "Completed required checks" -actions BROWSE -timeout 10 -appIcon $cci_logo)
case $response in
  "@TIMEOUT") echo "Alerter timedout -->" ;;
  "BROWSE") gh pr view --web ;;
  **) echo "Alerter ? --> $ANSWER" ;;
esac

Upvotes: 0

Paschalis
Paschalis

Reputation: 12291

Notify on an already running process:

  • Go to EditMarks and AnnotationsAlertsAlert on next mark
  • or use Shortcut: A

iTerm will literally keep an eye of your terminal (Spooky eye!, on the top right corner).
Once the command is finished, it will issue a notification.


Requirement: Shell Integration:

  • iTerm2Install Shell Integration
  • NOTE: integration will not issue notifications until iTerm2 is restarted.

Use Case:

We launched a command, underestimated completion time, and we don't want to cancel or just wait for completion.

Upvotes: 356

Mark Setchell
Mark Setchell

Reputation: 207345

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, when the command has finished, e.g.

sleep 20

# wait 5 seconds before realising this will take 20 seconds
notify<Enter>

Upvotes: 71

leonardo
leonardo

Reputation: 1714

Install the iTerm2 shell integration

curl -L https://iterm2.com/shell_integration/install_shell_integration_and_utilities.sh | bash

Execute your command and concatenate the attention app, e.g.

./task && ~/.iterm2/it2attention once

It'll cause the iTerm app to bounce it's icon once the job is complete.

You also have other attention options:

$ .iterm2/it2attention -h
Usage:
  it2attention start
    Begin bouncing the dock icon if another app is active
  it2attention stop
    Stop bouncing the dock icon if another app is active
  it2attention once
    Bounce the dock icon once if another app is active
  it2attention fireworks
    Show an explosion animation at the cursor

Upvotes: 7

MaSza
MaSza

Reputation: 465

You can also use terminal-notifier which use mac os system notifications. To install it via Home brew just:

$ brew install terminal-notifier

Then if you want to display notification when your job/process is done use something like this

$ <your job/process command> && echo 'Completed' | terminal-notifier -sound default

And this display like this:

enter image description here

You can also change sound and icon of notifications. More info in github repo: https://github.com/julienXX/terminal-notifier

Upvotes: 8

junjian.xu
junjian.xu

Reputation: 123

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.

Upvotes: 12

Farhan Salam
Farhan Salam

Reputation: 1485

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.

Upvotes: 104

baf
baf

Reputation: 4661

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.

Upvotes: 22

Related Questions