Saturday, 16 February 2013

Creating notifications in Plasma Desktop

Here's something very useful: if you ever wanted to trigger a Plasma Desktop notification from the shell, here's how you do it:

$ kdialog --title "Some meaningful title" --passivepopup "Whatever you want the notification to display." 10

I used this to notify me of any errors when automatic backup is run, because the backup application (written for Gnome) doesn't have any notifications built in.

The number 10 at the end of the command defines the popup duration in seconds. However, there must be a default maximum duration defined somewhere, because I couldn't get the popup to stay on for more than 30 seconds. Well, this should be enough anyway, because the notification does stay in the Notifications part of the system tray until you remove it by hand.

If you are trying to display a notification from a shell script, don't forget to  put

export DISPLAY=':0'

before the kdialog command, for obvious reasons.

The kdialog command is very flexible, and it supports a number of different modal dialogs. Check out the official tutorial here.

No comments:

Post a Comment