Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] How do I use notify-send from root VT
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 306
Location: Limerick, Ireland

PostPosted: Sun Jun 05, 2011 8:21 am    Post subject: [Solved] How do I use notify-send from root VT Reply with quote

Hi,

I have a small script that runs as a wicd hook. I'd like it to pop up a notification on the user screen using notify-send, but of course the script runs as root and can't connect to the X display. In my script, I set DISPLAY=:0.0 and run the notify-send command using sudo -u <myuser> notify-send... If I do this from a root console (not in xterm, on the VTs) it works, but my script produces an error (GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed) when run from wicd.

What is the right way to send a visual notification to all user's logged in to X from a system script?
_________________
Adopt an unanswered post today


Last edited by sirlark on Tue Jun 07, 2011 10:45 am; edited 1 time in total
Back to top
View user's profile Send private message
DSHugo
n00b
n00b


Joined: 26 Aug 2007
Posts: 46

PostPosted: Sun Jun 05, 2011 12:26 pm    Post subject: Reply with quote

You could try something along the lines of
Code:
su <your_regular_user> -c 'DISPLAY=:0 notify-send hello'

That works for me, at least, since I only have one desktop user.
Back to top
View user's profile Send private message
DSHugo
n00b
n00b


Joined: 26 Aug 2007
Posts: 46

PostPosted: Sun Jun 05, 2011 12:33 pm    Post subject: Reply with quote

You might also try it this way:
Code:
xuser=$(who | grep ":0" | awk '{print $1}' | tail -n1)
su "$xuser" -c 'DISPLAY=:0 notify-send hello'

You get the user, who's logged in on :0 display, then send your notification to him/her. But, I guess, this is not the correct way to send notifications.
You might try to do this, though:
Code:
wall "hello"

Dunno about other desktops, but KDE catches these kind of messages, and displays them perfectly. You don't need to set any variables, and will also get these on terminal.
Back to top
View user's profile Send private message
sirlark
Guru
Guru


Joined: 25 Oct 2004
Posts: 306
Location: Limerick, Ireland

PostPosted: Tue Jun 07, 2011 10:44 am    Post subject: Reply with quote

@DSHugo: Thanks!

So I tried your method, and then something slightly different. Turns out you need to set DISPLAY in the outer shell before calling su, as in

Code:
                for u in /home/*; do
                        if [[ -x $u/.wicd/postconnect ]]; then
                                username=`echo $u | sed 's:^/home/::'`
                                DISPLAY=$(who | awk "/$username.*\(:0.*\)$/ {print \$5}" | sed 's/(\([^)]\+\))/\1/' | head -n 1) su -c $u/.wicd/postconnect `echo $u | sed 's:^/home/::'` &
                        fi
                done


The notify-send commands are in my user's .wicd/postconnect scripts, and they work perfectly.
_________________
Adopt an unanswered post today


Last edited by sirlark on Tue Jun 07, 2011 3:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
M
Guru
Guru


Joined: 12 Dec 2006
Posts: 432

PostPosted: Tue Jun 07, 2011 1:02 pm    Post subject: Reply with quote

You could try to use https://github.com/mgorny/sw-notify-send/ . It is in portage, I used it with uam (automounter).
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum