Ubuntu – How to prevent the screen from either dimming or the screen-lock starting when watching YouTube

power-management

My screen brightness used to dim after a few seconds to preserve battery. This is default in Ubuntu 12.04. However when watching video it should not dim.

This works correctly when I watch videos using native applications like VLC. With in-browser video, however, the screen is not prevented from dimming.
This is very annoying as you have to move your cursor every 10 seconds or so.

I used to use Mac OSX where I had the same dimming settings and Flash videos were taken into account correctly.

Anyone an idea how you can make YouTube prevent your screen from dimming?

Best Answer

HOWTO: Disable screen saver while Flash is running

Run the following command in terminal:

mkdir -p ~/bin

Open gedit, or your preferred text editor and type this:

#!/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

Save this file as ~/bin/flash_saver.sh.

Go back into terminal and run:

chmod +x ~/bin/flash_saver.sh

To run this, go into terminal and type:

~/bin/flash_saver.sh

If you prefer, you can set this script to run at logon by doing the following:

  1. Run the program "Startup Applications"
  2. Click "Add"
  3. Under name type "FlashMonitor" or something you will recognise
  4. Under command type ~/bin/flash_saver.sh
  5. Under comment (if you want) type a brief description. E.g. "Stops screen turning off when Flash is running"

Source: HOWTO: Disable screen saver while Flash is running - ubuntuforums