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

Tags:

Answer: 1

3 hours ago

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?

Added by: Lexie Wisozk

Answer: 2

35 hours ago

HOWTO: Disable screen saver while Flash is running

Create a bash text file containing

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

Make the script executable by running:

chmod +x ~/path/to/script/flash_saver.sh

Run the script:

~/path/to/script/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 the path to the script
  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

Added by: Dr. Paula Roob

Answer: 3

3 hours ago

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.

Added by: Gino Block

Answer: 4

16 hours ago

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

Answer: 5

36 hours ago

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/

Answer: 6

1 hours ago

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/

Added by: Roxane Towne

Answer: 7

21 hours ago

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
Added by: Cleora Denesik

Answer: 8

9 hours ago

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.

Answer: 9

24 hours ago

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".

Added by: Dr. Jorge Johns

Answer: 10

20 hours ago

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).

Added by: Toy Haley MD

Answer: 11

22 hours ago

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.

Answer: 12

29 hours ago

Solution for HTML5 playback in Chrome

Overview

The following script disables the screensaver if it finds an active full-screen Chrome session. By default it will run a check every 5 minutes. The script will automatically resume the screensaver if either of the following three conditions are met:

  • window is not full-screen
  • window is not in focus
  • window does not exist anymore

Script

#!/bin/bash

## Variables ##

ChromeWmClass="Google-chrome"
FullScreenProperty="_NET_WM_STATE_FULLSCREEN"
CheckInterval="300" # check every 5 minutes

## Main ##

while true; do

  sleep "$CheckInterval"

  ActiveWinID=$(xdotool getactivewindow)

  if [[ -z "$ActiveWinID" ]]; then
    continue
  fi

  ActiveWinProp=$(xprop -id "$ActiveWinID")

  if echo "$ActiveWinProp" | grep "$FullScreenProperty" > /dev/null 2>&1 \
  && echo "$ActiveWinProp" | grep "WM_CLASS" | grep "$ChromeWmClass" > /dev/null 2>&1
    then
      if [[ -z "$SuspendingID" ]]; then
        echo "Suspending screensaver for $ActiveWinID"
        xdg-screensaver suspend "$ActiveWinID"
        SuspendingID="$ActiveWinID"
      elif [[ "$ActiveWinID" = "$SuspendingID" ]]; then
        echo "$ActiveWinID is already suspending  screensaver."
      elif [[ -n "$SuspendingID" ]]; then
        echo "Resuming screensaver for $SuspendingID"
        xdg-screensaver resume "$SuspendingID"
        echo "Suspending screensaver for $ActiveWinID"
        xdg-screensaver suspend "$ActiveWinID"
        SuspendingID="$ActiveWinID"
      fi
    else
      if [[ -n "$SuspendingID" ]] \
      && xprop -id "$SuspendingID" > /dev/null 2>&1
        then
          echo "Resuming screensaver for $SuspendingID"
          xdg-screensaver resume "$SuspendingID"
          SuspendingID=""
        else
          echo "No change."
      fi
  fi
done
Added by: Garrett Haley

Answer: 13

3 hours ago

The simplest nonintellectual approach which is desktop-agnostic and relies on xdotool would be to simulate a key stroke every N seconds.

I use a script called heartbeat.sh:

#!/bin/bash
while : 
do
    nice -n 1 xdotool key shift
    date +%T ## show some sign of life
    sleep 100
done

I launch the script while I play the video, and then stop it when it is not needed anymore.

xdotool can be installed with sudo apt-get install xdotool.

If you also want to have some kind of automatic audio detection, and you are ok with a PulseAudio-specific recipe, then below is a variation of the solution above that checks if audio is playing:

#!/bin/bash

while : 
do
    if [[ ! -z $(pacmd list-sink-inputs | grep RUNNING) ]] ; then
        echo 'Audio is playing. Inhibiting screensaver'
        nice -n 1 xdotool key shift ;
    else
        echo 'No audio detected'
    fi
    date +%T ## show some sign of life
    sleep 100
done

If using Alsa then the test would probably be something like (untested):

if [[ ! -z $(grep RUNNING /proc/asound/card*/pcm*/sub*/status) ]] ; then...

A potential downside of this solution is that your screen will not sleep even if you are just listening to music or radio, but I assume that in most cases this is not an issue.

Added by: Albertha Upton PhD

Answer: 14

6 hours ago

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.
Added by: Karley Walker

Answer: 15

3 hours ago

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

You can add this PPA using this command

sudo add-apt-repository ppa:n-muench/vlc
Added by: Chandler Toy

Answer: 16

19 hours ago

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?

Added by: Savanna Dickens

Answer: 17

17 hours ago

For those using Ubuntu-Gnome 14.04 there is a simple yet useful Extension called Caffeine which provides a toggle icon which allows you to disable the light dimming and screen saver behaviour from the top bar with a click.

The extension can be installed following this link to the Gnome-Shell Extensions website:

https://extensions.gnome.org/extension/517/caffeine/

Source: comments' section in this article:

http://www.maketecheasier.com/prevent-ubuntu-sleep-while-watching-video/

Added by: Emery Terry

Answer: 18

24 hours ago

This is my solution:

https://github.com/yanyingwang/shanghai-tools/blob/master/kit/the-bund-light.md

https://github.com/yanyingwang/shanghai-tools/blob/master/kit/the-bund-light.sh

Just download the the-bund-light.sh and add it to startbooting application:

sudo apt-get install xdotool

cd ~ && wget https://raw.githubusercontent.com/yanyingwang/shanghai-tools/master/kit/the-bund-light.sh

cat >> ~/.config/autostart/the-bund-light.sh.desktop <<EOF
[Desktop Entry]
Type=Application
Exec=$HOME/shanghai-tools/kit/the-bund-light.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[zh_CN]=TheBundLight
Name=TheBundLight
Comment[zh_CN]=
Comment=
EOF

CAUTION: the Exec's value in the code should be path of the-bund-light.sh in your computer.

Answer: 19

15 hours ago

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".

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

Added by: Rossie Weber

Answer: 20

29 hours ago

I use the following script as a workaround:

#!/bin/bash
while true
do
   xdotool key Shift_L
   sleep 1m
done

It simulates a left shift key press once every minute, which prevents the screen from going dim. The drawback of this, of course, is that you have to run the script every time you watch youtube. On the other hand, it is simple and works with most, if not all, configurations.

You may need to install this

sudo apt-get install xdotool
Added by: Valerie Hodkiewicz

Answer: 21

10 hours ago

The script at the above top does not work for me on Ubuntu 14.04 LTS Unity. Here its updated variant which works:

#!/bin/bash

id_saved=0
sac_saved=0
sbat_saved=0
dim_saved=false

ss_save()
{
    id_saved=`gsettings get org.gnome.desktop.session idle-delay`
    sac_saved=`gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout`
    sbat_saved=`gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout`
    dim_saved=`gsettings get org.gnome.settings-daemon.plugins.power idle-dim`
}

ss_set()
{
    gsettings set org.gnome.desktop.session idle-delay "$1"
    gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout "$2"
    gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout "$3"
    gsettings set org.gnome.settings-daemon.plugins.power idle-dim "$4"
}

ss_on()
{
    ss_set "$id_saved" "$sac_saved" "$sbat_saved" "$dim_saved"
}

ss_off()
{
    ss_set 0 0 0 false
}

trap ss_on EXIT

already_off=0
flash_on=0
ss_save

while true; do
    if top -bcw 200 | sed -e '1,/PID/d' | head -1 | grep flash > /dev/null
    then
        flash_on=1
        off_count=0
    else
        off_count=`expr $off_count + 1`
        echo "flash_off_count=$off_count"
        if [ $off_count -gt 5 ]; then
            flash_on=0
        fi
    fi

    if [ "$flash_on" = "1" -a "$already_off" = "0" ]; then
        echo "screensaver: off"
        ss_off
        already_off=1
    elif [ "$flash_on" = "0" -a "$already_off" = "1" ]; then
        echo "screensaver: on"
        ss_on
        already_off=0
    elif [ "$already_off" = "0" ]; then
        echo "screensaver: save possibly new params"
        ss_save # user may update the values
    fi

    sleep 30
done

BTW, this script disables screensaver ONLY when the video is playing, i.e. when flashplayer is in the top of CPU consumers.

Added by: Dane Marvin

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9