Activating KDE 4 notifications from bash scripts
Asked Answered
W

4

26

I have a bash script activated by crontab and running in background. I would like to add to it the ability to send notifications during the execution. My KDE 4 desktop has a fancy notification system which pops out non-modal messages from the tray bar, and this would be perfect for my needs. So I was searching for a way to generate these notifications from a bash scripts, but I have almost no knowledge of the KDE platform and so I'm stuck. Can anybody point me to a solution?

Winkler answered 4/9, 2009 at 14:59 Comment(2)
What's the notification system you use, if you mind me asking?Esophagus
If it's OK to forget about the integration with the notification area of your DE, you may use the xmessage command (from x11-utils), which purpose is to be the "X-based /bin/echo", i.e. it just pops up a minimal dialog window.Estefanaestel
T
38

kdialog's passive popup option can be used.

kdialog --passivepopup <text> <timeout>

Example:

kdialog --passivepopup 'This is a notification' 5
Triune answered 4/9, 2009 at 15:5 Comment(1)
On my system this command sends a notification at the up-right corner of the screen, with a blue background and white text.Concealment
H
20

You may also use notify-send (on Debian-based systems, install the libnotify-bin package):

notify-send -i 'dialog-information' 'Summary' '<b><font color=red>Message body.'

To my best knowledge, this should work on several window managers (such as KDE and Gnome).

Edit: HTML formatting of the message will only work with certain notification daemons and should thus be avoided.

Highroad answered 22/9, 2011 at 22:21 Comment(2)
Great advice in this answer: I learned that you can power the body with html and that the first text is the subject of the notification.Minister
To my surprise, I have notify-send installed on my Arch Linux with KDE, but not kdialog. This doesn't seem to be a norm, as kdialog is part of kdebase, but obviously, there are systems out there that have libnotify installed (optional dependency of dolphin) but not kdialog.Snowslide
M
2
kdialog --passivepopup 'message including html' timeout

is an option for KDE where the timeout is not necessary. you can tune this even with adding a headline (--title) and so on --> see kdialog --help

on the one hand it is worth mentioning, that kdialog was installed on my openSuSE KDE4 system whereas notify-send is not installed here.

on the other hand the advantage of notify-send is that you can use it with different desktop environments

Materiality answered 21/1, 2014 at 19:26 Comment(0)
M
0

Confirm that notify-send works with XFCE4 (Debian-based Mint), except the <b><font color=red> didn't work for me. For some reason it made the Message body text dark grey (virtually illegible), so I left that html out and the header ('Summary') and body text both come up white.

What is cool is that you can put an absolute path to the icon your prefer -- e.g. -i '~/myapps/foobarapp/icons/64x64/64x64.png'

Mcdavid answered 17/4, 2017 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.