#!/bin/bash

# This script asumes you are running nautilus (using gnome).
# Credit to Chief677 @ http://ubuntuforums.org/showpost.php?p=6087197&postcount=2 for inspiration.
# by Stefan "nsg" Berggren, 2009

# config
source /etc/snotify

if [ "x$5" = "x2nd" ]; then
	if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
		PIDS=`pgrep -u $USERNAME nautilus`
		for pid in $PIDS; do
			DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
			export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
		done
	fi

	if [ -z "$3" ]; then
		TIMEOUT=$DEFAULT_TIMEOUT
	else
		TIMEOUT="$3"
	fi

	if [ -z "$4" ]; then
		$NOTIFY "$1" "$2" -t $TIMEOUT
	else
		$NOTIFY "$1" "$2" -t $TIMEOUT -i $4
	fi
else
	su s -c "$0 '$1' '$2' '$TIMEOUT' '$4' '2nd'"
fi
