Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

14 Answers 14

up vote 33 down vote accepted

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

share|improve this answer
3  
If I could I'd vote this up +5. The script from the ubuntu forum is incredibly well written as is your answer. Also big thumb up for actually including the source. –  con-f-use Aug 2 '12 at 13:18
25  
xkcd.com/196 –  SpellingD Aug 2 '12 at 17:23
3  
This indeed only works for Firefox. Anyone able to rewrite this for multiple-browser support? –  Steven Roose Oct 16 '12 at 15:12
1  
I am running Ubuntu Gnome 13.10 and this does not seem to work for me. Anyone else out there who also have problems on Ubuntu 13.10? Or maybe it's just Gnome 3.8 that overruns this behavior somehow? –  Lindhea Nov 6 '13 at 20:50
1  
will it work with html5 video player? –  kdureidy May 9 at 0:29

The VLC in this PPA in addition to being a current version of VLC also correctly implements screen saver inhibition.

https://launchpad.net/~n-muench/+archive/vlc?field.series_filter=lucid

You can add this PPA using this command

sudo add-apt-repository ppa:n-muench/vlc

share|improve this answer

You should not only check the screensaver options, but also the power management options, especially the "Put display to sleep when inactive for ..." option.

Note that on laptops, there are two settings with that name: when the laptop is running on AC power and when it is running on battery.

share|improve this answer

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.

share|improve this answer
    
This is running pretty fine on 12.04, Thank you! –  Geppettvs D'Constanzo Sep 24 '12 at 19:47
    
Thanks for contributing a solution, but this is the best solution? Is this not a bug? It's got to be a bug. This happens on gnome, but not on unity. –  BullfrogBlues Feb 27 '13 at 15:47
    
I am now on 12.04 and I still use that application, not to stop the screensaver but to disable decrease of screen brightness quickly. For what I saw if it is a bug, it is in the browser: it should be his responsibility to inhibit the screensaver when in fullscreen. –  Salem Mar 3 '13 at 19:00
    
Doesn't install in 13.10 –  NoBugs Dec 7 '13 at 4:36
    
@NoBugs It does not work in 13.04/10: bugs.launchpad.net/caffeine/+bug/1174400 –  Salem Dec 8 '13 at 23:31

It depends somewhat on what version of Ubuntu you are using. In 11.10, you can find "System Settings" in by clicking the gear icon in the top right corner of the screen. Select this, and in the dialog that pops up, select "Screen". You can set the amount of time that your computer will be idle before the screen blanks with the dropdown menu, or disable that feature by clicking the button labeled "Lock".

-screenshot not posted due to lack of reputation-

If you have an older system, you may have to look elsewhere for this setting, but it is there somewhere.

share|improve this answer
4  
Yeah, but I do not want to disable it permanently. –  ste_kwr Feb 20 '12 at 10:38

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
share|improve this answer

For a pre-rolled equivalent to the script supplied by @njallam, with a neat little Gnome UI element, try the Caffeine applet:

https://launchpad.net/caffeine
http://ubuntu-tweak.com/app/caffeine/

share|improve this answer
    
I had Caffeine installed but didn't see you had to activate it to let it work. Thanks! –  Steven Roose Aug 4 '12 at 9:59
    
Info from Caffeine developers: “Flash video support is gone, as it was too complicated to keep it working.” So you can forget Flash video checkbox in its settings. However, if you are using Firefox, add plugin-container to the list of programs and Caffeine will activate on Flash videos properly (deactivation will be delayed slightly, as plugin-container doesn't unload immediately when you close the tab with video, it takes several minutes). –  whtyger Mar 18 at 8:43

For those that like full or manual control at their hands

This command line can set the screensaver delay time:
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0

Use "0" (zero) to keep it on or another value to define the delay in seconds.

The following script will keep the screen on until some key is pressed.

#!/bin/bash

# 
# To turn screen sleep time off for a while then back on
#
# by desgua 2013/01/27
#

# Getting the previous configuration
back=$(gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac)

# Defining the restore function
function RESTORE {

gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac $back
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery $back
gsettings set org.gnome.desktop.session idle-delay $back

bmin=$(echo "$back / 60" | bc)
#notify-send "Screen sleep time restored to $bmin minutes."
echo
echo "Screen sleep time restored to $bmin minutes."
echo 

exit 0
}

# Making sure the user don't mess up...
trap 'RESTORE && exit 0' INT HUP

# Disabling sleep time
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0
gsettings set org.gnome.desktop.session idle-delay 0

echo
echo "Screen sleep time turned off."
echo 

#notify-send "Screen sleep time turned off."

# Waiting for user to press some key and then restore the previous configuration
read -n 1 -p 'Press any key to turn it on again. ' b

RESTORE

exit 0

How to run a script:
1. Copy the text into an empty file,
2. Save the file,
3. Make the file executable,
4. Run it from a terminal.

Enjoy ;-)

share|improve this answer

Use Caffeine : ppa page.

How to install:

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

How to run:

  1. Hit Alt + F2, then type caffeine.

  2. Click the "Caffeine" icon, then click "Disable Screensaver".

share|improve this answer
1  
I don't intend to disable screensaver. Anyway, I tried caffeine, but doesn't work in any way. I don't think that is updated to the latest version of Gnome. –  Radu Rădeanu Jun 4 '13 at 15:57
    
@RaduRădeanu caffeine disables the screensaver of your computer it has nothing to do with your web browser. –  Alvar Jun 4 '13 at 16:02
    
@Alvar It has if you wish... Anyway, didn't worked for me. –  Radu Rădeanu Jun 4 '13 at 16:06

For those who are using a screensaver other than gnome-screensaver (which is the default screensaver in Ubuntu starting with the 11.10 version) this answer may be helpful.

Personally, I didn't change out gnome-screensaver for something else and, I don't know for what reasons, Caffeine doesn't work for me in any way (maybe is outdated).

That being said, starting from others' bash scripts (this, this and this), I managed to make a new script, gnome_screensaver_off.sh that works perfectly for what I intended when YouTube is using Flash player for rendering videos.

Disable gnome-screensaver while YouTube is using Flash player

Open a terminal and run next commands followed by instructions:

  • mkdir -p bin - this command will make a bin directory in your home folder if you don't already have it.
  • gedit ~/bin/gnome_screensaver_off.sh -this will create the new file gnome_screensaver_off.sh in gedit.
  • Copy and paste there next script:
#!/bin/bash

# Getting the previous configuration
back=$(gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac)

screensaver_is_off=0
delay=$[$back - 10]

# Defining the restore function
function restore {
    gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac $back
    gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery $back
    gsettings set org.gnome.desktop.session idle-delay $back

    bmin=$[$back / 60]
    #notify-send "Screen sleep time restored to $bmin minutes."

    notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "Screen sleep time restored to $bmin minutes."
}

# Defining the disable_screensaver function
function disable_screensaver {
    # Making sure the user don't mess up...
    trap 'restore && exit 0' INT HUP

    # Disabling sleep time
    gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0
    gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0
    gsettings set org.gnome.desktop.session idle-delay 0

    notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "Screen sleep time turned off."
}

while true; do
    if [ "$delay" -le "50" ]; then
        sleep 50
    else
        sleep $delay
    fi
    flash_on=0

    #Check if Chrome, Chromium or Firefox is open with a flash video running on it
    if pgrep -lfc ".*((c|C)hrome|chromium|firefox|).*flashp.*" > /dev/null ; then
            flash_on=1
    else
        flash_on=0  
    fi

    if [ "$flash_on" -eq "1" ] && [ "$back" -ne  "0" ] && [ "$screensaver_is_off" -eq "0" ]; then
        disable_screensaver
        screensaver_is_off=1
    elif [ "$flash_on" -eq "0" ] && [ "$screensaver_is_off" -eq "1" ]; then
        restore
        screensaver_is_off=0
    fi
done

exit 0
  • Save the file and close it.
  • Go back into terminal and run: chmod +x gnome_screensaver_off.sh - to grant execute access for the script.
  • To run your new script, run ~/bin/gnome_screensaver_off.sh.

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

  1. Search in Dash for Startup Applications, open it and click Add.
  2. Under name type "YouTube Monitor" or something you will recognise.
  3. Under command type "/home/$USER/bin/gnome_screensaver_off.sh" (change $USER with your username).
  4. Under comment (if you want), type a brief description (e.g. "Stops screen turning off when Flash player is running in browser").

Disable gnome-screensaver while YouTube is using HTML5 player

The question remains open in this sense...

Thanks for the suggestions offered by: fossfreedom, Meer Borg, njallam, desgua and others.

share|improve this answer

Not entirely what you're after but this little script would register a mouse movement each time it was run. You could drop it into cron to run once every x-amount-of-time. That would stop the screen from turning off, and a 1 1 movement of the mouse is barely noticeable if it runs when you're NOT watching a video

#!/bin/bash
#move the mouse
xte 'mousermove 1 1' 

I totally got this idea from an xkcd comic by the way. http://xkcd.com/196/

share|improve this answer

A little old, but here it is with multiple browsers support:

#!/bin/bash -eu

# List your browsers here
browsers_list=( "firefox" "chrome" "chromium" "opera" )

# 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

idle_off=0

while true; do

    sleep 60

    for browser in "${browsers_list[@]}" ; do
    for pid in `pgrep $browser` ; do

        flash_on=0
        if [ -O /proc/$pid/maps ] && 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
            idle_off=1
        elif [ "$flash_on" = "0" ] && [ "$ss_on" = "false" ] && [ "$idle_off" = "1" ]; then
            gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
            idle_off=0
        fi

    done
    done

done

Just save the script somewhere, chmod +x it, and add it to the StartupApplications. There might be a way to list all available browsers using something like:

update-alternatives --list x-www-browser

But I don't know how to handle the fact that some executables don't have the name than their processes (for instance /usr/bin/google-chrome runs as chrome).

share|improve this answer

Webupd8 had an article about Caffeine and Lightson.sh to disable the screen saver while Flash or HTML5 videos are playing. The Lightson script works for both Firefox and Chrome and can be set to include VLC. I hope this will help.

In case the code provided by Webupd8 to install the script follows:

mkdir -p ~/scripts && cd ~/scripts

wget https://raw.github.com/hotice/lightsOn/master/lightsOn.sh

chmod +x lightsOn.sh
share|improve this answer
1  
The method used in that script (lightsOn.sh) to detect if the browser utilizes HTML5 player is not really good. In fact, the method determines if Firefox or Chromium is in full-screen... In rest the article is good and your answer is most approached about what I asked. –  Radu Rădeanu Jun 11 '13 at 18:20
1  
I have been to doing a little more research found a script based of CPU or Network activity. It located at on the Mint Forums it might give you a little better control. Enjoy watching YouTube. –  Garry Jun 12 '13 at 2:00

You may simply execute/set this command while startup :

gconftool --type string --set /apps/compiz-1/plugins/fade/screen0/dim_unresponsive false   

Also can you try unchecking the hardware acceleration option on firefox?

share|improve this answer
1  
I said this before: I don't intend to disable screensaver. I want only to prevent my screen from dimming when watching YouTube. –  Radu Rădeanu Jun 10 '13 at 6:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.