sábado, 14 de febrero de 2015

Desktop notifications with notify-send - a mini how-to

Sometimes is useful to put pop-up messages on running scripts, for example when running a back up or anything else, in order to get informed about the progress. The command discussed here is

notify-send

A nice notify-send pop-up message


Display pop-up messages as ordinary user

Supposing that you have an script for make a back-up of your personal documents as

#!/bin/bash
cp -r /home/user/documents /home/user/backups/

And you want to know when the backup has finished without checking the console.

All you have to do is adding a line such as

notify-send "BackUp Completed!" "Hi peasant, the back up process is done"

So the new script looks like

#!/bin/bash
cp -r /home/user/documents /home/user/backups/
notify-send "BackUp Completed!" "Hi peasant, the back up process is done"

To see more options read the man page for notify-send.


Display pop-up messages as root

Supposing that you run the script as root and your wall username is user, yo can add this line to your script

export DISPLAY=:0.0 && sudo -u user notify-send "MsgTitle" "Message"



No hay comentarios.:

Publicar un comentario