Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #174821 > unrolled thread

Desktop notifications?

Started byTeemu Likonen <tlikonen@iki.fi>
First post2016-11-17 17:10 +0100
Last post2016-11-19 09:50 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.debian.user


Contents

  Desktop notifications? Teemu Likonen <tlikonen@iki.fi> - 2016-11-17 17:10 +0100
    Re: Desktop notifications? Michael Milliman <michael.e.milliman@gmail.com> - 2016-11-17 21:20 +0100
    Re: Desktop notifications? Reco <recoverym4n@gmail.com> - 2016-11-18 09:10 +0100
      Re: Desktop notifications? Teemu Likonen <tlikonen@iki.fi> - 2016-11-19 09:50 +0100

#174821 — Desktop notifications?

FromTeemu Likonen <tlikonen@iki.fi>
Date2016-11-17 17:10 +0100
SubjectDesktop notifications?
Message-ID<sExqa-2W6-9@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

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.

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".

-- 
/// Teemu Likonen   - .-..   <https://github.com/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

[toc] | [next] | [standalone]


#174830

FromMichael Milliman <michael.e.milliman@gmail.com>
Date2016-11-17 21:20 +0100
Message-ID<sEBk6-5tb-3@gated-at.bofh.it>
In reply to#174821

[Multipart message — attachments visible in raw view] — view raw

On 11/17/2016 10:09 AM, 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.
>
> 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".
I don't know whether this qualifies as a work around that you are not 
interested in, but I have found that this works.  From you script use 
the following:

    sudo -u <username> notify-send foo

Since the script is running with root privileges, sudo will not need a 
password to run the notify-send command as a lesser privileged user.  I 
haven't tried this from a script, but did do it from the keyboard.  I 
verified that notify-send would not send a notification to me when 
sudo'ed as root, and then used the above command.  It did indeed work.  
The <username> that you use is the username that you are normally logged 
in as.

-- 
73's de Mike, WB5VQX

[toc] | [prev] | [next] | [standalone]


#174844

FromReco <recoverym4n@gmail.com>
Date2016-11-18 09:10 +0100
Message-ID<sEMpg-4tE-11@gated-at.bofh.it>
In reply to#174821
	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

[toc] | [prev] | [next] | [standalone]


#174872

FromTeemu Likonen <tlikonen@iki.fi>
Date2016-11-19 09:50 +0100
Message-ID<sF9vs-2Ae-7@gated-at.bofh.it>
In reply to#174844

[Multipart message — attachments visible in raw view] — view raw

Reco [2016-11-18 11:03:31+03] wrote:

> For your notification to work you need to define the correct value of
> DBUS_SESSION_BUS_ADDRESS environment variable for your backup script.

That is the kind of information I wanted. I had assumed, perhaps
naively, that desktop notification system would automatically just work:
easily send notifications on any desktop sessions that are available at
the moment. Well, not quite, but I learned new things anyway. Thanks.

-- 
/// Teemu Likonen   - .-..   <https://github.com/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web