How to prevent my screen from either dimming or the screen-lock starting when watching YouTube?

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


EDIT

This probably will not work if you are using an Ubuntu version newer than 12.04 (have tried in 13.04 and 13.10 and it just does not work at all). It seems the main developer is not working anymore in this project, so the chances of it being fixed are not good.


In my system (Ubuntu 11.10) i use Caffeine. You can try if it works in Xubuntu too. It adds a notification area icon where you can enable/disable screensaver for some programs. To install Caffeine, do the following:

sudo add-apt-repository ppa:caffeine-developers/ppa
sudo apt-get update
sudo apt-get install caffeine

Then execute in a terminal:

caffeine -p &

You can then choose the programs that should disable the screensaver:
vlc for VLC, mplayer for Movie Player, etc.

Caffeine Preferences

Hope it helps.


There is a nice little script on GitHub called lightsOn which should do the trick you want.

Basically it looks for full screen video (flash in firefox or chromium, mplayer or vlc) and if so disable xscreensaver and also the auto power-manager dim screen capability.

from the script itself:

HOW TO USE: Start the script with the number of seconds you want the checks
for fullscreen to be done. Example:
 "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer,
 VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so.
 You want the number of seconds to be ~10 seconds less than the time it takes
 your screensaver or Power Management to activate.
 If you don't pass an argument, the checks are done every 50 seconds.

Thus call the script from your autostart folder as per my answer here.

Adjust the script for whether you are running flash/vlc/mplayer

remember to give the script execute rights to run i.e.

chmod +x lightsOn.sh