#!/bin/bash

if [ $# -gt 1 ]
then
	shift
fi
if [ $# -gt 0 ]
then
	ssh -q ${1} ${0}
else
	GNOME_SESSION_PID=`pidof gnome-session`
	if [[ "${GNOME_SESSION_PID}" == "" ]]
	then
		exit 1
	fi
	# http://ubuntuforums.org/showpost.php?p=7656946&postcount=6
	if [[ -n $SSH_CLIENT ]]; then
	    export DBUS_SESSION_BUS_ADDRESS=`cat /proc/$(pidof gnome-session)/environ | tr '\0' '\n' | grep DBUS_SESSION_BUS_ADDRESS | cut -d '=' -f2-`
	fi

	test "`LC_ALL=C DISPLAY=\:0.0 gnome-screensaver-command -q 2>&1`" == "The screensaver is inactive"
fi
