Results 1 to 10 of 46

Thread: HOWTO: Disable screen saver while Flash is running

Hybrid View

  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,170
    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
    Oct 2005
    Beans
    7

    Re: HOWTO: Disable screen saver while Flash is running

    doesn't work with google chrome. but it still great script

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
  •