How to send a desktop notification in KDE from a daemon
Asked Answered
M

2

5

I have a daemon (netplugd) which can take some actions when my cable is being plugged in or out. These actions can be defined via a bash script. How can I send a notification (as a different user) to my desktop (using bash) that will inform me about the state of the cable.

I have tried the following:

notify-send and knotify --passivepopup but the daemon shows that $DISPLAY is not set.

Monosaccharide answered 9/1, 2012 at 9:0 Comment(1)
little hacky, but if you know what your display should be you can set it, e.g. system("export DISPLAY=:0.0; notify-send \"Hello World\""). $DISPLAY is not set because the daemon is started by process 1 (init), which is independent of user/graphical session, etc. A better way, conceivably, would be to query the system for active graphical sessions and determine their display variables.Stickler
L
5

You could use the write command, which can be caught by KDE's Write daemon, and will be displayed in the Notification area in your KDE desktop. The Write daemon is running by default; if not, you can change this in System settings -> System administration -> Startup and Shutdown -> Service manager.

By default the notification produces a sound, and a pop-up which lasts for about four seconds. After that, you'll find a reminder of the notification on your taskbar. You can manage the behaviour of this notification to some extent in System settings -> Common appearance and Behaviour -> Applications and System notifications -> Manage notifications -> Applications tab -> Event source: Local system message service.

Lammers answered 17/11, 2013 at 10:47 Comment(1)
I also found the wall command which seems more suitable. Thank you.Monosaccharide
A
9

You can also try

echo hello > /dev/pts/0
Almeta answered 29/10, 2020 at 20:23 Comment(1)
That works for me in KDE Plasma on NixOS.Fungible
L
5

You could use the write command, which can be caught by KDE's Write daemon, and will be displayed in the Notification area in your KDE desktop. The Write daemon is running by default; if not, you can change this in System settings -> System administration -> Startup and Shutdown -> Service manager.

By default the notification produces a sound, and a pop-up which lasts for about four seconds. After that, you'll find a reminder of the notification on your taskbar. You can manage the behaviour of this notification to some extent in System settings -> Common appearance and Behaviour -> Applications and System notifications -> Manage notifications -> Applications tab -> Event source: Local system message service.

Lammers answered 17/11, 2013 at 10:47 Comment(1)
I also found the wall command which seems more suitable. Thank you.Monosaccharide

© 2022 - 2024 — McMap. All rights reserved.