disable screen saver when looking at flash videos(youtube, vimeo, etc)

Run this script at startup of Gnome.

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

turn_it_off=0
sleepcomputer0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
sleepdisplay0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_ac`

# run loop forever
while true; do
  # interval between checks
  sleep 30
  SS_off=0
  # make id variable of window in focus
  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
  # make pid array of every command with libflashplayer in full(-f) command
  for pid in `pgrep -f libflashplayer` ; do
    # check if window in focus is our libflashplayer
    if [ $pid == `xprop -id $current_window_id | grep PID | cut -d" " -f3` ]
      then SS_off=1
    fi
  done

# check to see if xine is being used
#  if pgrep xine > /dev/null; then
#    SS_off=1
#  fi
#
# check to see if current application is fullscreen
#  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
#  if xprop -id $current_window_id | grep "_NET_WM_STATE_FULLSCREEN" > /dev/null; then
#    SS_off=1
#  fi

  # read current state of screensaver
  ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`

  # change state of screensaver as necessary
  if [ "$SS_off" = "1" ] && [ "$ss_on" = "true" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
    turn_it_off=1
  elif [ "$SS_off" = "0" ] && [ "$ss_on" = "false" ] && [ "$turn_it_off" = "1" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int $sleepdisplay0
    turn_it_off=0
  fi
done

Reference: http://ubuntuforums.org/showthread.php?p=10832670#post10832670

One thought on “disable screen saver when looking at flash videos(youtube, vimeo, etc)”

  1. Updated script with Wimp(music application)

    #!/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
    
    #turn_it_off=0
    sleepcomputer0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
    sleepdisplay0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_ac`
    sleepcomputer1=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_battery`
    sleepdisplay1=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_battery`
    
    # run loop forever
    while true; do
      # interval between checks
      sleep 50
      SS_off=0
    
      # turn off if libflashplayer is in fullscreen
      # make id variable of window in focus
      current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
      # make pid array of every command with libflashplayer in full(-f) command
      for pid in `pgrep -f libflashplayer` ; do
    
        # uncomment for debugging
        #echo $pid
        #xprop -id $current_window_id | grep PID | cut -d" " -f3
        #echo -e
    
        # check if window in focus is our libflashplayer
        if [ $pid == `xprop -id $current_window_id | grep PID | cut -d" " -f3` ]
          then SS_off=1
        fi
      done
    
      # turn of sleep if Wimp is running
      if [ `pgrep Wimp` ]; then wimp=1; else wimp=0; fi
    
      # read current state of screensaver
      ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`
    
      # read current state of power manager
      pm_on=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
    
      # change state of screensaver as necessary
      if [ $SS_off == 1 ] && [ $ss_on == true ]; then
    #    echo "Slår av skjermsparer"
        gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_battery --type int 0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_battery --type int 0
        gconftool-2 -s /apps/gnome-power-manager/backlight/battery_reduce --type bool false
      elif [ $SS_off == 0 ] && [ $ss_on == false ]; then
    #    echo "Slår på skjermsparer"
        gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int $sleepdisplay0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_battery --type int $sleepcomputer1
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_battery --type int $sleepdisplay1
        gconftool-2 -s /apps/gnome-power-manager/backlight/battery_reduce --type bool true
      elif [ $wimp == 1 ] && [ $pm_on != 0 ]; then
    #    echo "Slår av sleep"
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_battery --type int 0
      elif [ $wimp == 0 ] && [ $pm_on == 0 ]; then
    #    echo "Slår på sleep"
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
        gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_battery --type int $sleepcomputer1
      fi
    done
    

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>