LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-23-2008, 11:29 AM   #1
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 485

Rep: Reputation: 31
Question How do I run a scripts when screen saver activates?


I have a scripts, say foo.sh, I want to activate when the screen saver is active and deactivate when the user comes back on line.

Basically foo.sh is some custom processing I want to do in the computer idle times. I figure hooking into the screen saver or monitor power saver mode some how would be the ideal way to detect this.

Does anyone have any suggestions.
 
Old 02-24-2008, 05:56 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I don't know which script would need to be edited in order to stick your command in it (I too would like to find out), but I just thought I would mention that there's also another way you could approach this: Have a cron job run every minute checking to see whether a screensaver is running. If there is, your program gets started; if there's not (and your program is running), your program is stopped; if there's not (and your program isn't running), nothing is done.

Yes, this method sucks compared to what you currently have in mind, but it's an alternative nevertheless. Like I said, I too look forward to learning which script to edit in order to do this in a more kosher way. I don't have anything serious which I'd want to execute when the screensaver comes on but making an ogg/mp3 play would be cool.
 
Old 02-24-2008, 11:59 AM   #3
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 485

Original Poster
Rep: Reputation: 31
Good I idea... but if I was going to create a script like that I'd want to base it on more than the screen saver.

ie: what if the computer is on but no users are logged in. Also account for system load.


I have discovered something about gnome screen savers. Creating them is very easy. I could design a new screen saver which calls say slideshow and my program. So far I've just found this... I haven't actually played with it yet.

Code:
[mcarter@snow-faerie screensavers]$ cat /usr/share/applications/screensavers/frogs-slideshow.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Frogs
Comment=Display a slideshow of pictures of frogs
Exec=slideshow --location=/usr/share/pixmaps/backgrounds/frogs/
TryExec=slideshow
StartupNotify=false
Terminal=false
Type=Application
Categories=GNOME;Screensaver;

Programs run by the screen saver are in /usr/libexec
[mcarter@snow-faerie screensavers]$ ls -l /usr/libexec/gnome-screensaver/        
total 96
-rwxr-xr-x 1 root root 21748 2007-11-12 16:34 floaters
-rwxr-xr-x 1 root root    34 2007-10-02 10:23 f-spot-screensaver
-rwxr-xr-x 1 root root 17688 2007-11-12 16:34 popsquares
-rwxr-xr-x 1 root root 29744 2007-11-12 16:34 slideshow
 
Old 02-25-2008, 11:57 AM   #4
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 485

Original Poster
Rep: Reputation: 31
Lightbulb

Well no luck on the screen saver front. However I did find something to work. My script runs through a loop. The processing maxes the CPU for about 2 seconds. Then moves to the next.

So I put in a check after each processing to see if the tty has been idle for more than 15 minutes. (main command being "w") Does the trick. I just wish there was a better way to handle time.

Code:
      echo "Pausing for Computer to be idle"
      ########################################################
      # Check if the PC (tty console) is idle.  If idle for
      # more than 15 minutes.  If so do the run.  For this to
      # work script needs to be started with the pc on reboot
      ########################################################
      let IdleYN=0
      while [ $IdleYN -eq 0 ] ; do
         IdleString=`w | grep tty | awk {'print $5'}` 
         let IdleYN=1

         ################################################################
         # Loop through all users who are currently idle
         ################################################################
         for IdleTime in $IdleString ; do
           let Idle=0
           let Minutes=0

           if [ "`echo $IdleTime | grep "s"`" != "" ] ; then
                   let Idle=0
           else
             if [ "`echo $IdleTime | grep -e "m" -e "day"`" == "" ] ; then
               let Minutes=`echo $IdleTime | awk -F: {'print $1'}`
               if [ $Minutes -gt 15 ] ; then
                   let Idle=1
               else
                   let Idle=0
               fi
             else
               let Idle=1
             fi
           fi


           ################################################################
           # If the Idle time is 0 for any tty console set the master to 0
           # That way if two users are logged in it will only run if all 
           # users are idle
           ################################################################
           if [ $Idle -eq 0 ] ; then
                 let IdleYN=0
           fi

         done

         if [ $IdleYN -eq 0 ] ; then
           sleep 15
         fi
      done
 
Old 07-01-2008, 11:31 AM   #5
Slick666
Member
 
Registered: Feb 2006
Distribution: Ubuntu 8.04; Debian Etch
Posts: 167

Rep: Reputation: 33
I'm looking to do the same. I want the machine to do some work when the screensaver is on and stop when the screen saver is off. One idea I had that might work is to base to activation and deactivation on whether the screen is locked or not. I almost ALWAYS lock my screen so I thought I could use that as a trigger but I really don't know how or where to get started looking.

Any thoughts?
 
Old 07-01-2008, 12:56 PM   #6
MikeyCarter
Member
 
Registered: Feb 2003
Location: Orangeville
Distribution: Fedora
Posts: 485

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Slick666 View Post
I'm looking to do the same. I want the machine to do some work when the screensaver is on and stop when the screen saver is off. One idea I had that might work is to base to activation and deactivation on whether the screen is locked or not. I almost ALWAYS lock my screen so I thought I could use that as a trigger but I really don't know how or where to get started looking.

Any thoughts?

I went a totally different route and looked for when the computer tty sessions were idle for 15 minutes.

Code:
      echo "Pausing for Computer to be idle"
      ########################################################
      # Check if the PC (tty console) is idle.  If idle for
      # more than 15 minutes.  If so do the run.  For this to
      # work script needs to be started with the pc on reboot
      ########################################################
      let IdleYN=0
      while [ $IdleYN -eq 0 ] ; do
         IdleString=`w | grep tty | awk {'print $5'}` 
         let IdleYN=1

         ################################################################
         # Loop through all users who are currently idle
         ################################################################
         for IdleTime in $IdleString ; do
           let Idle=0
           let Minutes=0

           if [ "`echo $IdleTime | grep "s"`" != "" ] ; then
                   let Idle=0
           else
             if [ "`echo $IdleTime | grep -e "m" -e "day"`" == "" ] ; then
               let Minutes=`echo $IdleTime | awk -F: {'print $1'}`
               if [ $Minutes -gt 15 ] ; then
                   let Idle=1
               else
                   let Idle=0
               fi
             else
               let Idle=1
             fi
           fi


           ################################################################
           # If the Idle time is 0 for any tty console set the master to 0
           # That way if two users are logged in it will only run if all 
           # users are idle
           ################################################################
           if [ $Idle -eq 0 ] ; then
                 let IdleYN=0
           fi

         done

         ################################################################
         # Override idle check for testing
         ################################################################
         if [ -s /var/run/cf_geopack_remote.pid ] ; then
                echo "Exists: /var/run/cf_geopack_remote.pid skipping idle check"
                 let IdleYN=1
         fi

         if [ $IdleYN -eq 0 ] ; then
           sleep 15
         fi

      done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dark screen after screen saver O_o!! elekt Ubuntu 0 07-25-2007 10:54 PM
Feisty: Screensavers Run Slowly During Idle Time, and Fast During screen Saver Test. bburgy Ubuntu 4 06-27-2007 11:05 PM
ATI 9200 SE screen flicker in screen saver gargamel Slackware 12 07-09-2005 05:10 PM
How to turn off screen blanking screen saver in run level 3? Arodef Linux - Software 1 01-04-2005 01:50 PM
Dell 510M Letterbox / Small screen in X and Console before fb activates dezza Linux - Laptop and Netbook 3 11-09-2004 04:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration