Results 1 to 3 of 3

Thread: Problem using notify-send as root

Hybrid View

  1. #1
    Join Date
    May 2007
    Location
    Chennai,India
    Beans
    24
    Distro
    Ubuntu 10.04 Lucid Lynx

    Question Problem using notify-send as root

    When I use notify-send in scripts run by using '/etc/crontab' notifications are not displayed in Hardy.
    In gusty doing the following
    Code:
    DBUS_SESSION_BUS_ADDRESS="dbus session address of the user" sudo -u "user" notify-send "Some text"
    displays notifications but when I use this in Hardy I get the following error
    Code:
    libnotify-Message: Unable to get session bus: Failed to connect to socket /tmp/dbus-'some random text': Connection refused
    Is there any other way to make scripts executed by '/etc/crontab' to display notifications in Hardy?
    Last edited by ashikahamed; May 2nd, 2008 at 12:10 PM.

  2. #2
    Join Date
    Dec 2006
    Beans
    3

    Re: Problem using notify-send as root

    Hey,

    I know this is an old question but I worked out a solution right now and maybe you still need a soulution

    I'm running a sync script hourly with cron and want to be notified via libnotify, so I had the same problem as you had Here is my code piece which does the notification for me:

    Code:
    #!/bin/sh
    
    init_notify() {
    	user=`whoami`
    	pids=`pgrep -u $user nautilus`
    	for pid in $pids; do
    		# find DBUS session bus for this session
    		DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
    		# use it
    		export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
    	done
    }
    
    notify() {
    	if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
    		init_notify
    	fi
    	
    	title=$1
    	text=$2
    	timeout=$3
    	
    	if [ -z "$title" ]; then
    		return
    	fi
    	if [ -z "$text" ]; then
    		text=$title
    	fi
    	if [ -z "$timeout" ]; then
    		timeout=5000
    	fi
    	
    	notify-send "$title" "$text" -t $timeout
    }
    Just copy&paste these two funtions into your script and just type 'notify "title" "text" 5000' in your script where you want to send a notification.
    Don't forget to write the correct username in the "init_notification()" function.

    c,Ya
    Last edited by Chief677; November 2nd, 2008 at 02:46 PM.

  3. #3
    Join Date
    Oct 2009
    Location
    Leesville, Louisiana, USA
    Beans
    Hidden!
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Problem using notify-send as root

    what about if another user calls the script. I have a second user calling scripts on my computer which requires me to get a notification when the script is called.

    How do I set it up so that script notifies my main desktop?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •