Alert when terminal program finishes running? [duplicate]
Solution 1:
There's couple of ways, both with &&
(logical AND) operator (which runs only when last command succeeded). If you want to run notification regardless of whether command succeeded or failed, use semicolon ;
instead of &&
.
-
Graphical
myscript.sh && notify-send 'DONE'
-
Audio:
myscript.sh && aplay /usr/share/sounds/speech-dispatcher/test.wav
Note, you can use any audio file instead of the one I used here.
-
Both:
myscript.sh && aplay /usr/share/sounds/speech-dispatcher/test.wav && notify-send 'DONE !'
Solution 2:
You can use zenity to display a popup.
After your shell command, append
&& zenity --info --text "STRING"
Solution 3:
I suggest using libnotify's notify-send
for notifications. I've created the following script to do this:
#!/bin/bash
$1 && \
notify-send -u critical -i info 'Command execution finished' "The command '$1' terminated successfully" || \
notify-send -u critical 'Command execution failed' "The command '$1' exited with errors"
If you save above script in a file called e.g. nexec
and make it executable using chmod +x nexec
, and move the program to a directory in your shells PATH
variable, (e.g. /usr/local/bin/
), you can run any command with
nexec 'long-time-command some arguments'
E.g.
nexec 'sudo apt-get update && apt-get dist-upgrade'
libnotify will (at least it does so on my system, I assume this can differ between different desktops) display notifications marked as 'critical' until they are being dismissed manually (e.g. by clicking on them). As you can take from the code, you will receive a different notification if the command returns a non-zero result.
Solution 4:
Have you ever heard of undistract-me? It seems it fits your needs and its code it's on github.
I think the package is in the official Ubuntu repos, so should be sufficient
sudo apt-get install undistract-me
then you have to close and reopen any terminal you have, just to let the changes take effect and you can test it with a simple
sleep 11
Remember to change your active window, otherwise you won't see any notification.