blank-me-not.sh

A wrapper script to disable power saving while running the application of your choice.

Purpose

Normally you'd want your screensaver to come on automatically when your system doesn't see any keyboard or mouse input for some period of time. This saves on both power and wear-and-tear on your components. However, there are many legitimate situations where temporarily disabling your screensaver makes perfect sense:

  • Watching feature-length movies
  • Putting on a slideshow or video presentation
  • Playing video games with a joystick or gamepad

These needs in mind, blank-me-not.sh acts as a wrapper which can temporarily disable power saving features while the application of your choice is running.

Features

  • Disables power saving only while your application is running.
  • Simple operation – Requires no special arguments to function.

Requirements

Application Information
bash The Bourne Again SHell is probably required, though this script is simple enough that it may not be a hard requirement.
movietime movietime is a script which, while activated, disables power saving features such as your screen saver.

Installation

Once the requirements are met, you simply need to place the script someplace in your path. There are two ways to accomplish this:

  1. Copy and paste the code into a blank file on your system, then make it executable.
  2. Download the script directly to your hard drive, then make it executable.

In either case, you will probably need root privileges first, e.g.:

 su -

…or:

sudo su -

1. The copy & paste method

If you will be copying and pasting the script, use your favorite text editor to create the file in question. In this example I'll use vim (though any text editor will do):

 vim /usr/local/bin/blank-me-not.sh

…then paste in the code on this page, save, and exit.1) Finally, make the resulting file executable:

chmod 755 /usr/local/bin/blank-me-not.sh

2. Download the script directly

Alternately, you could skip the text editor and just grab the file directly:

wget http://tuxhelp.org/pub/scripts/blank-me-not.sh -O /usr/local/bin/blank-me-not.sh && chmod 755 /usr/local/bin/blank-me-not.sh

Or the same, but with curl instead of wget:

curl http://tuxhelp.org/pub/scripts/blank-me-not.sh > /usr/local/bin/blank-me-not.sh && chmod 755 /usr/local/bin/blank-me-not.sh

Usage

Usage is easy; just run blank-me-not.sh followed by the program for which you'd like power saving disabled. When the program exits, blank-me-not.sh will automatically re-enable power saving for you.

You can also edit application shortcuts to automatically disable power saving whenever that application is run. For example, if I want to change my startup shortcut for the ZSNES emulator, it would go from this:

[Desktop Entry]
Encoding=UTF-8
Name=zsnes
Comment=A Super Nintendo Entertainment System (TM) emulator
Exec=zsnes
Icon=zsnes.xpm
Terminal=false
Type=Application
Categories=Application;Game;2DGraphics;Emulator

…to this:

[Desktop Entry]
Encoding=UTF-8
Name=zsnes
Comment=A Super Nintendo Entertainment System (TM) emulator
Exec=blank-me-not.sh zsnes
Icon=zsnes.xpm
Terminal=false
Type=Application
Categories=Application;Game;2DGraphics;Emulator

The Code

#!/bin/bash
 
#########################################################
#   Disable power saving while running an application	#
#########################################################
# By Christopher A. Wadge, 10/28/2010			#
#							#
# http://tuxhelp.org/scripts/blank-me-not.sh		#
#							#
# Licensed under the GPL version 3. A copy of the GPL	#
# version 3 is included with this script.  If the file, #
# COPYING, is not included, you can find the GPL 	#
# version 3 at the following URL online:		#
#							#
# http://www.gnu.org/licenses/gpl-3.0.html		#
#########################################################
 
# This script's name:
PROGRAM_NAME="blank-me-not.sh"
# Date of last revision:
PROGRAM_DATE="11/05/10"
 
## VARIABLES ##
# The following are pre-determined variables that are not answered by the script.
#####
 
## Executable Path ##
 
# Location of 'movietime' script. If you don't have it, you can get it here:
# http://linuxtidbits.wordpress.com/2009/09/08/movietime-stop-powersaving-to-watch-a-movie/
MOVIETIME="/usr/local/bin/movietime"
 
## !!! Attention Users: Editing below this line is not advised unless you really know what you're doing.
 
## FUNCTIONS ##
# Define each function that we will call in scripting later
#####
 
Error ()
{
        echo "[FATAL] Unfortunately we've encountered an unrecoverable error. Now quitting."
        if [ `ps -A | grep -c movietime` = 1 ] ; then
        $MOVIETIME || Kill_Movietime
        fi
        if [ `ps -A | grep -c movietime` = 1 ] ; then
        Kill_Movietime
        fi
        exit 1
}
 
Kill_Movietime ()
{
if [ `ps -A | grep -c movietime` = 1 ] ; then
	echo "'movietime' won't quit; trying to kill it..."
	kill `ps -A | grep movietime | cut -d " " -f2` || $( echo "[ERROR] Unable to kill movietime! Bailing out..." ; exit 1 )
fi 
if [ `ps -A | grep -c movietime` = 1 ] ; then
	echo "Still running, killing 'movietime' harder..."
	kill -9 `ps -A | grep movietime | cut -d " " -f2` || $( echo "[ERROR] Unable to kill movietime! Bailing out..." ; exit 1 )
fi
if [ `ps -A | grep -c movietime` = 1 ] ; then
	echo "[ERROR] $PROGRAM_NAME wasn't able to stop 'movietime':"
	ps -A | grep movietime
	echo "Do you own that process? Now bailing out..."
	exit 1
fi
	echo "OK, 'movietime' is no longer running."
}
 
Print_Help ()
{
	echo ""
	echo "==== $PROGRAM_NAME ($PROGRAM_DATE) ===="
	echo ""
	echo "Description:   Disable power saving while running an application."
	echo ""
	echo "Usage:         $PROGRAM_NAME <APPLICATION> [OPTIONS]"
	echo ""
	echo "Dependencies:  'movietime' power-management script:"
	echo "                http://tinyurl.com/movietime-script"
	echo ""
	exit 0
}
 
Sanity_Check ()
{
if [ ! -e $MOVIETIME ] ; then
	echo "[ERROR] The 'movietime' script is not in the expected location: '$MOVIETIME'"
	echo "        If you need movietime, you can get it here: http://tinyurl.com/movietime-script"
	echo "        Otherwise, you can correct the path by editing the VARIABLES section of this script."
	NOTSANE=1
fi
if [ ! -z $NOTSANE ] ; then
	Error
fi
}
 
## SCRIPTING ##
# Here's where we actually do all the work
#####
 
if [ "$1" = "--help" ] ; then
	Print_Help
elif [ -z "$1" ] ; then
	Print_Help
fi
Sanity_Check
# Launch your application with movietime:
if [ `ps -A | grep -c movietime` = 0 ] ; then
        $MOVIETIME || $( echo "[ERROR] A problem was detected while running 'movietime'. Bailing out..." ; Kill_Movietime ; Error )
        "${@}"
else
        "${@}"
fi
# Stop movietime if it's still running:
if [ `ps -A | grep -c movietime` = 1 ] ; then
        $MOVIETIME || Kill_Movietime
fi
exit 0
1) ':wq' to write and quit in VIM
scripts/blank-me-not.sh.txt · Last modified: 2012/01/22 17:32 (external edit)
Back to top
CC Attribution-Noncommercial-Share Alike 3.0 Unported
This server powered by Debian Linux Valid CSS Driven by DokuWiki This site works best with Firefox Recent changes RSS feed Valid XHTML 1.0