You might consider checking how long the screen saver has been running.
#!/bin/bash
screensaver="atlantis"
t=$(
# check for the screensaver
ps h -o start -C $screensaver |\
# hh:mm:ss -> seconds
awk -F: '{print $1"*3600+"$2"*60+"$3}' |\
bc -l 2>/dev/null | sort -n | tail -1
)
if [ "$t" == "" ]
then
exit 0
fi
n=$(
date "+%T" |\
awk -F: '{print $1"*3600+"$2"*60+"$3}' |\
bc -l 2>/dev/null
)
runtime=$(( $n - $t ))
if [ $runtime -gt 3600 ] || [ $runtime -lt 0 ]
then
echo shutdown -h now
fi
Using the time value requires subtracting now from then to get the run time.
Also, in my case, the screensaver program which appears in the process table will vary depending on which screensaver is selected. So, the above program assumes that 'atlantis' is the current screen saver.