View previous topic :: View next topic |
Author |
Message |
sirlark Guru
Joined: 25 Oct 2004 Posts: 306 Location: Limerick, Ireland
|
Posted: Sun Jun 05, 2011 8:21 am Post subject: [Solved] How do I use notify-send from root VT |
|
|
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 |
|
|
DSHugo n00b
Joined: 26 Aug 2007 Posts: 46
|
Posted: Sun Jun 05, 2011 12:26 pm Post subject: |
|
|
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 |
|
|
DSHugo n00b
Joined: 26 Aug 2007 Posts: 46
|
Posted: Sun Jun 05, 2011 12:33 pm Post subject: |
|
|
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:
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 |
|
|
sirlark Guru
Joined: 25 Oct 2004 Posts: 306 Location: Limerick, Ireland
|
Posted: Tue Jun 07, 2011 10:44 am Post subject: |
|
|
@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 |
|
|
M Guru
Joined: 12 Dec 2006 Posts: 432
|
|
Back to top |
|
|
|