6

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.

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. Commented Oct 30, 2015 at 16:42

2 Answers 2

11

You can also try

echo hello > /dev/pts/0
Sign up to request clarification or add additional context in comments.

1 Comment

That works for me in KDE Plasma on NixOS.
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.

1 Comment

I also found the wall command which seems more suitable. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.