[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Desktop notifications?



	Hi.

On Thu, Nov 17, 2016 at 06:09:04PM +0200, Teemu Likonen wrote:
> I have a backup script that runs once a day with root privileges. It's
> handled by systemd timer and service units. I would like to have a
> desktop notification text when the backup is ready.
> 
> What I have tried so far: I don't use normal desktop, only i3 window
> manager. I installed notify-osd package and started its daemon as a
> normal user. Running a command "notify-send foo" shows "foo" text like I
> expected. But when "notify-send" runs as root no notification text
> appear anywhere.

It's expected to work that way, see below.

> How can I get notifications working in plain window manager setup? And
> hopefully not only this backup script example but for other programs
> too, like Network Manager's notifications. I'm not really interested in
> work-arounds like "DISPLAY=:0 xmessage -timeout 5 foo".

For your notification to work you need to define the correct value of
DBUS_SESSION_BUS_ADDRESS environment variable for your backup script.
In the normal case (i.e. your i3 WM session) this variable is set by
/etc/X11/Xsession.d/75dbus_dbus-launch script, which generates the value
of the variable randomly.

Hence you'll need either:

1) Ditch your setup for 'systemd timer and service units', and run your
script from WM session via sudo, and use "notify-send" on script
completion.

2) Use klugde like this in the script:

if [ "`pgrep -c i3`" = "1" ]; then
	export `strings /proc/$(pgrep -c i3)/environ | grep DBUS_SESSION_BUS_ADDRESS`
	notify-send -t 10000 "Backup job" "Done"
fi


Of course, you can workaround the problem by running "dbus-launch" in
the script itself, but it has disadvantage of running notify-osd as
root, and the need of providing the means of accessing X display to root.

Reco


Reply to: