4

I am running Debian and wish to make use of notify-send. But notify-send doesn't give me any notification unless I have one of the following running:

# either:
/usr/lib/notification-daemon/notification-daemon
# or:
/usr/lib/notify-osd/notify-osd

I'd like to run one of these as a service, rather than letting them be jobs in my shell. However, when I create a startup script for them in /etc/init.d (using skeleton as a template), trying to start the service results in the following output, and notify-send displays no notifications:

(notification-daemon:14467): Gtk-WARNING **: cannot open display:

Jellicle
  • 401

4 Answers4

3

The scripts in /etc/init.d control system-wide startup scripts, while you want to start a service for your individual login session. There are ways to do this for all login sessions for all users, but they depend on how your system is set up. Likewise, there are ways to do this for your individual login session, but it depends on what type of session you are using. (E.g., GNOME, XFCE, KDE, fvwm, whatever.)

What you probably want to do is configure your session manager, desktop environment, or window manager to start /usr/lib/notify-osd/notify-osd at startup. For example, I use fvwm via xsession, so I have in my ~/.xsession the following:

#!/bin/sh

# Other programs I need at startup like xscreensaver and urxvtd ...

/usr/lib/notify-osd/notify-osd &

exec fvwm
HalosGhost
  • 4,790
elb
  • 31
  • Note that debian Jessie will switch to systemd, so sysv-related advice will largely no longer be up-to-date. – HalosGhost Oct 07 '14 at 14:46
1

'cannot open display' means that your binary requiers X server which is not running. You have to amend your startscript so that notify-send starts after X server. Post your script if you have issues with that.

user1700494
  • 2,202
0

To add to @elb's answer:

When I added the line to ~/.xsession it broke the autologin of the machine to the point where logging in became impossible (I guess because the .xsession file was continuously being read each time I logged in?)

Instead I put the same contents in an ~/.xsessionrc file, which did not previously exist on my system. But it did the trick!

A.Meijer
  • 311
0

Add the following systemd unit file:

# ~/.config/systemd/user/notification-daemon.service
[Unit]
Description=Notification Daemon
After=display-manager.service

[Service]
Restart=on-failure
RestartSec=1
ExecStart=/usr/lib/notification-daemon-1.0/notification-daemon

[Install]
WantedBy=default.target

Note that display-manager.service might be different on your system, the trick is to make it After something that starts the X server.

As your user, run

systemctl --user enable --now notification-daemon.service

The --now is optional, it's just like doing start at the same time.

jpkotta
  • 433