#!/bin/bash ### Mac OS X Desksaver Script ### by Michael Lee ### v1.00.00, 2009-01-22 ### About Desksaver # # This script is a wrapper for commands used to display a screensaver module on # the desktop and restore the normal desktop wallpaper. # # You can specify an optional screensaver module name to override the default # set in System Preferences. For example, if you have the "RSS Visualizer" set # as your screensaver but you want to have Flurry on your desktop, type: # desksaver on Flurry # to override the system setting. When specifying module names, use a name from # the Screen Savers list in System Preferences, not a path or file name. # # Technical note: we can use nohup, but screen # (1) doesn't leave nohup.out files everywhere and # (2) can be killed with -HUP # ### License # # Copyright (C) 2009 Michael Lee # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # "constant" definitions to make the code below nicer DESKSAVER_ENGINE='/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background' MY_NAME=`basename $0` # Display usage info and exit function display_usage () { echo "Usage: $MY_NAME on [module name]" echo ' '"$MY_NAME off" exit 1 } # Return whether a ScreenSaverEngine is running in the background (on the Desktop) function already_running () { ps aux | grep "ScreenSaverEngine -background" | grep -qv "grep" } # We only support Mac OS X if [[ `uname -s` != "Darwin" ]]; then echo "This script only works on Mac OS X." exit 2 fi # We need at least one commandline argument if [[ $# == 0 ]]; then display_usage fi # See if the user wants to turn the desksaver on or off if [[ "$1" == "on" ]]; then if already_running; then echo "A screensaver is already running on your desktop." echo "Use the following command to stop it:" echo ' '"$MY_NAME off" exit 3 fi # Remove the "on" argument from the argument queue shift # See if the user specified a custom module name if [[ $# != 0 ]]; then echo "Using the screensaver module named '$*'" screen -d -m $DESKSAVER_ENGINE -module "$*" PID=$! else echo "Using the default screensaver module (set in System Preferences)" screen -d -m $DESKSAVER_ENGINE PID=$! fi elif [[ "$1" == "off" ]]; then if already_running; then killall -HUP ScreenSaverEngine echo "Desktop screensaver stopped." else echo "No screensaver is currently running on your desktop." exit 4 fi else display_usage fi