Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I sometimes fall asleep when using my computer. Is it possible to determine what time the screen saver turned on and therefore when I stopped using the computer and fell asleep?

share|improve this question
    
Which DE (gnome, kde, etc.)? –  nerdwaller Jul 10 '13 at 17:43
    
Are you using xscreensaver or a screensaver provided by your window manager? –  Breakthrough Jul 11 '13 at 19:39

1 Answer 1

up vote 2 down vote accepted

You can just write a bash script to check if the screensaver is running.

I wrote a quick one that you could background, of course things can be added to make it work nicely according to your needs

#!/bin/bash
while [ 1 ]
do
tester=$(ps aux | grep gimp | grep -v "grep") #or whatever your screensaver application is called
  if [[ "$tester" != '' ]]; then
  echo $tester > info.txt
  exit
fi
done

You can add a sleep 2 or something in the middle, and then just background it, but the program will have to be run again after every time your screensaver is run, you could probably set something up to check if its running or not in a cron, really the sky's the limit with these scripts.

in the end you'll get a ps aux line printed to a file and within that line it will have the time that the program started.

if you want to to continue, like a log for when the screen falls asleep, you can always change the > to a >> and that will append the new line each time.

I hope that this helps!

I just realized an easy way to make this more of a constant service:

#!/bin/bash
while [ 1 ]
do
tester=$(ps aux | grep gimp | grep -v "grep") #or whatever your screensaver application is called
  if [[ "$tester" != '' ]]; then
  echo $tester > info.txt
  while ["$(ps aux | grep gimp | grep -v "grep")" != '']
   do  
   sleep 2
   done
fi
sleep 15
done
share|improve this answer
1  
it depends on which screensaver you're using, if you read the file for the cosmos screensaver in RHEL, it executes a new process that you can detect. If you notice my script still has gimp in it, its just for testing purposes. But if you find which file the daemon is executing you can put that in instead and the script will work. the footers screensaver also works, and this is just using the gnome screensaver here is the exec code Exec=/usr/libexec/gnome-screensaver/floaters /usr/share/pixmaps/gnome-logo-white.svg please remove the downvote, my answer is complete –  Eric Jul 11 '13 at 19:16
    
Or to cut out the need for an additional service, you could always try adding date > info.txt to the exec above, that could work, but I don't know how altering the exec in that screensaver file would affect the performance of the screensaver. –  Eric Jul 11 '13 at 19:21
    
the downvote was not mine, however I will delete my comment. –  handuel Jul 11 '13 at 20:06
    
Does my answer seem acceptable now, I appreciate your upvotes –  Eric Jul 11 '13 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.