Page 1 of 5 123 ... LastLast
Results 1 to 10 of 46

Thread: HOWTO: Disable screen saver while Flash is running

  1. #1
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    HOWTO: Disable screen saver while Flash is running

    Summary
    When playing Flash video in Firefox, the screen saver is not disabled and so you are required to move your mouse every few minutes to prevent the screen saver from turning on. This is highly annoying. This guide provides a method to automatically disable the screen saver whenever Flash is being used in Firefox.

    Note: This method disables the screen saver regardless of what type of Flash program is running. It doesn't discriminate between a Youtube video and a Punch the Monkey ad.

    Implementation
    We are going to create a daemon that detects if the Flash shared library currently has any memory mapped. If it does, we disable the screen saver. If it doesn't, and we know that we previously disabled the screen saver, we turn it back on. First, we need to make sure we have a local bin directory:

    Code:
    mkdir -p ~/bin
    Next, save the following script as ~/bin/flash_saver.sh:

    Code:
    #!/bin/bash
    
    # Cleanup any bad state we left behind if the user exited while flash was
    # running
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
    
    we_turned_it_off=0
    
    while true; do
        sleep 60
        flash_on=0
    
        for pid in `pgrep firefox` ; do
            if grep libflashplayer /proc/$pid/maps > /dev/null ; then
                flash_on=1
            fi
            
            ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`
    
            if [ "$flash_on" = "1" ] && [ "$ss_on" = "true" ]; then
                gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled \
                    --type bool false
                we_turned_it_off=1
            elif [ "$flash_on" = "0" ] && [ "$ss_on" = "false" ] \
                    && [ "$we_turned_it_off" = "1" ]; then
                gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled \
                    --type bool true
                we_turned_it_off=0
            fi
    
        done
    done
    Next, we make the script executable:

    Code:
    chmod +x ~/bin/flash_saver.sh
    Now, we can turn it on by pressing F2 and running, "~/bin/flash_saver.sh". You can now either test it watching some Flash videos or just proceed to System->Preferences->Session and adding "flash_saver.sh" as one of your startup programs.

    Testing
    Watch some long Flash videos and verify that screen saver doesn't come on. Afterwards, close all tabs that have any Flash content on them and see if the screen saver now comes on as normal.
    Don't try to make something "fast" until you are able to quantify "slow".

  2. #2
    Join Date
    Sep 2006
    Beans
    3,165
    Distro
    Ubuntu Karmic Koala (testing)

    Re: HOWTO: Disable screen saver while Flash is running

    thanks, it is very handy when watching movies

  3. #3
    Join Date
    Jan 2008
    Beans
    21

    Re: HOWTO: Disable screen saver while Flash is running

    which part of this script I need if I just need a terminal command to disable the screen saver?

  4. #4
    Join Date
    Apr 2006
    Beans
    4

    Re: HOWTO: Disable screen saver while Flash is running

    sdennie, fantastic job with the script..thanks! One problem though. All parts of script seem to work except when I no longer have flash playing, or even close the browser all together, screensaver will not enable itself back to on?

    jackmcslay, see my post #7 here: http://ubuntuforums.org/showthread.p...13#post6858013

  5. #5
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Disable screen saver while Flash is running

    Quote Originally Posted by jkernsjr View Post
    sdennie, fantastic job with the script..thanks! One problem though. All parts of script seem to work except when I no longer have flash playing, or even close the browser all together, screensaver will not enable itself back to on?

    jackmcslay, see my post #7 here: http://ubuntuforums.org/showthread.p...13#post6858013
    I'm not sure what would cause this unless some other application has turned off the screen saver. The script goes out of its way to not touch things if something else has changed the settings. The other possibility is that you have some hung firefox process somewhere that is using flash but you can't see it.
    Don't try to make something "fast" until you are able to quantify "slow".

  6. #6
    Join Date
    Jan 2009
    Location
    USA
    Beans
    58

    Cool Re: HOWTO: Disable screen saver while Flash is running

    Thank you very much for this How-To but I don't know how to write codes and using the command line is no natural to me. I'm going to wait for Ubuntu 9.04 to come out and hope that this problem is solved in that version. Also this problem doesn't only occur in Flash, it occurs whenever I'm watching a video (full screen or not) such as on youtube, or just a regular mpg or avi file.

  7. #7
    Join Date
    Mar 2006
    Location
    Denmark - Copenhagen
    Beans
    2,165

    Re: HOWTO: Disable screen saver while Flash is running

    Will do this when I get home.. this really should be default setting IMO

  8. #8
    Join Date
    Aug 2007
    Location
    Chicago, IL, USA
    Beans
    1,429
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Disable screen saver while Flash is running

    Any way to only do this only while flash is in full screen, or only on certain websites?

    Good work by the way!

  9. #9
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Disable screen saver while Flash is running

    Didn't notice these questions. Sorry for the late replies:

    Quote Originally Posted by jackmcslay View Post
    which part of this script I need if I just need a terminal command to disable the screen saver?
    To disable:

    Code:
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    To enable:

    Code:
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    Quote Originally Posted by Thelasko View Post
    Any way to only do this only while flash is in full screen, or only on certain websites?

    Good work by the way!
    You should be able to. It's a bit more work than I'm willing to put into it but, here is a snippet I've pulled out of another script I wrote that only does stuff when a window named "foo" is active:

    Code:
        active_win_line=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
        active_win_id="${active_win_line:40}"
        
        if xwininfo -id $active_win_id | grep "foo" > /dev/null ; then
            # Do stuff
        fi
    Don't try to make something "fast" until you are able to quantify "slow".

  10. #10
    Join Date
    Sep 2008
    Location
    KCMO area
    Beans
    90

    Re: HOWTO: Disable screen saver while Flash is running

    I don't know if you are still watching this thread but I am having some difficulty with this. It looks like the script is working and setting the gconftool-2 setting correctly but the screen saver is still starting. I am running MythBuntu 8.10, pretty much vanila. I have the screen saver set to start after like 2 minutes. MythTV correctly stops it from activating. Here is the output from some commands while firefox has a hulu program playing and the screensaver is running. (I got these out of a putty session connected.)
    Code:
    curt@media1:~$ ps -A | grep flash_saver.sh
     5908 ?        00:00:00 flash_saver.sh
    curt@media1:~$ pgrep firefox
    17662
    curt@media1:~$ grep libflashplayer /proc/17662/maps
    b0990000-b12e2000 r-xp 00000000 08:01 724861     /usr/lib/adobe-flashplugin/libflashplayer.so
    b12e2000-b1316000 rw-p 00951000 08:01 724861     /usr/lib/adobe-flashplugin/libflashplayer.so
    curt@media1:~$ gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled
    false
    Now, that last setting never seems to go back to true, is that a problem? Anyone see anything obviously wrong?

    --
    [edit - research at work]
    Looks like it is possible Mythbuntu based on Xbuntu uses xscreensaver instead of gnome-screensaver. It looks like simply executing "xscreensaver-command -deactivate" periodically may provide a simulated mouse/keyboard movement. Issuing this every 60 seconds while flash is active could be an easy modification to that script. I will try changing it and report back when I have the chance to try this.
    Last edited by Boppy3125; May 12th, 2009 at 09:37 PM. Reason: Researching at work

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •