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.

Sangeeth Saravanaraj
  • 16,027
  • 21
  • 69
  • 98
Victor Dodon
  • 1,796
  • 3
  • 18
  • 27
  • 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. – Colin Oct 30 '15 at 16:42

2 Answers2

6

You can also try

echo hello > /dev/pts/0
Ramast
  • 7,157
  • 3
  • 32
  • 32
4

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.

AstroFloyd
  • 405
  • 5
  • 14