Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to manage the desktop screensaver Desktop
I loved the Screensaver in the Background hint, but I was tired of typing...
nice -n 20 /System/Library/Frameworks/ScreenSaver.framework/Resources/
ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background -module Random &
...every time I wanted to use it. So I wrote a little shell script to make it easier for me. I know it's not programmatically correct; this is because I'm lazy and this was at first only for my own use. It works, and that's what counts. If someone wants to take the time to correct it and post, feel free. Read the rest of the article for the script...

To install the script:
  1. Copy all of the text below to your clipboard
  2. Open a terminal window, and type sudo pico /usr/bin/saver. You'll probably have to get rid of line breaks put in for web display.
  3. Paste it all in
  4. Type control-x
  5. Type sudo chmod 755 /usr/bin/saver
  6. Type rehash
Now you're good to go. As the code implies, type saver -h to see your options.

[Editor's comment: You may not wish to save this to /usr/bin, where it may get overwritten by future updates from Apple. Instead, try putting it in a "bin" directory in your user's folder, or in /usr/local/bin, and then make sure that directory is in your $PATH variable; see this hint for a discussion on how to set the $PATH variable.]

The script:
#!/bin/sh

module=Random

if [[ $# -ne 0 ]]
then
if [[ $1 = -h ]]
then
echo "Usage:"
echo " saver random module"
echo " saver -h this help screen"
echo " saver -l list available modules"
echo " saver -k kill the running module"
echo " saver -m Modname use module Modname"
exit 0
fi

if [[ $1 = -l ]]
then
user=`users`
ls /Users/$user/Library/Screen\ Savers/ | grep .saver
ls /Library/Screen\ Savers/ | grep .saver
exit 0
fi

if [[ $1 = -m ]]
then
module=$2
fi

if [[ $1 = -k ]]
then
if [[ `ps -c | grep ScreenSaver` ]]
then
for id in `ps -c | grep ScreenSaver`
do
kill $id
break
done
fi
exit 0
fi
fi

if [[ `ps -c | grep ScreenSaver` ]]
then
for id in `ps -c | grep ScreenSaver`
do
kill $id
break
done
fi

nice -n 20 /System/Library/Frameworks/ScreenSaver.framework/Resources/
ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background -module $module &
The last line has been broken into two for easier reading; remove the line break and enter it on one line (no spaces) when pasting the code.
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[10,233 views]  

A script to manage the desktop screensaver | 7 comments | Create New Account
Click here to return to the 'A script to manage the desktop screensaver' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
easier way...
Authored by: PsiPhi on Aug 30, '02 06:28:27PM
I guess it's not really a big deal since you already did the legwork and people can just copy and paste, but an (IMO) easier way to do this is to put something like the following in your .cshrc (or whatever shell you use):

alias DTSaver 'cd /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS; ./ScreenSaverEngine -background'

Then just save the file, exit that terminal, open a new one and type "DTSaver" or whatever you called it. Of course, you can add the '&' and the '-module' if you like. I find it more convenient to just leave the ampersand off so I can control-c kill it and my screen "effects" are already set to random. Just hide that terminal and open a new one if you need to do other terminal stuff. Also, bear in mind (for those of you that don't know unix or the alias command), those are not apostrophes before the "cd" and after the "-background" those are called grave accents and are located below escape -- i.e. the tilde (~) key sans the shift modifier.

Works for me.

[ Reply to This | # ]
easier way...
Authored by: blgrace on Aug 31, '02 12:28:18AM

Ummm.. this doesn't work in my default tcsh shell for the following reasons.
1. They ARE apostrophes
2. putting the "cd" command before the rest of the commands will give you a "too many args" error.
I'm not a UNIX person at all but I figured out how to do it using the "pico" text editor.
-------------------Try This---------------------------
I used "wow" as my alias/shortcut in this example
pico .tcshrc <return>
alias wow '/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background' <return>
Just make sure your text string is all on the same line and no breaks.
To save the file press <control>x then y for yes and then finaly <return>
open a new terminal window and type in your alias and there you have it.
<control>c will stop it.



[ Reply to This | # ]
easier way...
Authored by: foon on Aug 31, '02 12:18:39PM

You're right in that that is an easier way to use the basic functionality. That's what I used at first. But I wanted more flexibility, which would have been really hard to do in an alias, or would possibly have required multiple aliases, which would have gotten klunky.

Foon



[ Reply to This | # ]
Great Job!
Authored by: DAC on Aug 30, '02 06:38:30PM

Taking the time to share those personal tips and tricks are what really make OS X a much more fun place to be. Keep up the good work.



[ Reply to This | # ]
timkered script
Authored by: lithosyork on Sep 29, '02 01:22:35PM
i tinkered with foons script and then i started again! heres a new version - comments welcome, bug fixes etc theres usage info and a few comments, works pretty much the same, you can choose a few more options.

i keep my stuff in /usr/local/bin . call it what you like.

cheers...

--cut here--
#!/bin/sh
#  above line specifies which shell to useto execute this file
#  author: rob stone.  psychology, university of york, uk. modified by
#  idea from foon (Joel Kraut) on  mscosxhints see
#  http://www.macosxhints.com/article.php?story=20020830050630964

#set -x
#debugging switch - uncomment to see what is happening

#shell variables set in one place for ease
PATH=/bin:/sbin:/usr/bin:/usr/sbin  # set to make sure nothing odd gets run
SAVER="/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine "
USER=`users`

NICE="nice -n 20 "        # run at a lower priority so as to free up resources
BKG=0                     # set to 1 if you always wnat this and you can alter the behaviour of -b
SWITCHES=" -background "  # set to run in the background,

function usage () {
# show the usage info with the options
    PROGNAME=`basename $0` ;
    echo "Usage: $0  [-d|-h|-k|-l]  [-b] [-f] [-r|-m modname]"
    echo "  $PROGNAME       use currently chosen module"
    echo "  $PROGNAME -b    background the task (&) and return control to terminal"
    echo "  $PROGNAME -d    display all the running screensaver modules and exit"
    echo "  $PROGNAME -f    display in the foreground - funky"
    echo "  $PROGNAME -h    show this help screen and exit"
    echo "  $PROGNAME -k    kill all the running screensavers and exit"
    echo "  $PROGNAME -l    list available modules for $USER and system and exit"
    echo "  $PROGNAME -m modname use module Modname"
    echo "  $PROGNAME -r    use the Random module"
    echo
    echo "Note: specifing more than one -r or -m will use the last one listed"
    echo
    exit 0 
}   


function killsavers() {
# get the ps lines for very occurence  the pid is the first 5 chars
    for ID in `ps -c | fgrep "ScreenSaverEn" | cut  -c1-5  `
    do
        kill $ID
    done
}  

# loop around the flags processong each one.
while [ $# != 0 ]
do
    case $1 in 
            -b) BKG=1
                shift
                ;;
            -d) ps -c  | fgrep "ScreenSaver"
                exit 0 
                ;;

            -f) SWITCHES=" -foreground " 
                shift
                ;;
            -l) echo "==== USER $USER  [ /Users/$USER/Library/Screen Savers] ======"
                ls  /Users/$USER/Library/Screen Savers/ | fgrep .saver
                echo "==== SYSTEM [/Library/Screen Savers/] ======"
                ls  /Library/Screen Savers/ | fgrep .saver
                exit 0
                ;;
            -k) killsavers
                exit 0 
                ;;
            -r) SWITCHES="$SWITCHES -module Random" 
                shift
                ;;
            -m) SWITCHES="$SWITCHES -module $2" 
                shift
                shift
                ;;  
                
            *)  usage  
                ;;
        esac
        
done

killsavers

case $BKG in
    1)  $NICE $SAVER $SWITCHES & ;;
    *)  exec $NICE $SAVER $SWITCHES  ;;
esac

-- cut here --
apologies for the double line spacing - dont know whats happening there !

[ Reply to This | # ]
cpu monitor as desktop
Authored by: tex210 on Sep 30, '02 05:32:25AM

i'm not a programmer, but i was wondering if screensavers were a type of app? the reason i'm wondering is that i want to run cpu monitor (or equivilent) as my desktop. I know it sounds useless, but i love leaving it running (expanded view) large to see my computer "think"(silly I know) but it floats above my desktop icons... is there a way to make a screensaver get the information on cpu usage and display an active graph? i'm thinking a screensaver to desktop method would be the only way to get this to work... Am i way off and just dreaming?



[ Reply to This | # ]
timkered script
Authored by: TigerPRO on Jun 22, '05 09:49:12AM

Just an update for using this script with Tiger. But it also enhances it's use under Panther. Adding following extra lines includes support for .slideSaver and .qtz (quart composer things) screen savers. Also by adding the "/System/Library/Screen Savers" directory, you will then be able to call each of the pre-installed screen saver modules as well.

Replace this line of code in the original script:

[code]
ls /Users/$user/Library/Screen\ Savers/ | grep .saver
ls /System/Library/Screen\ Savers/ | grep .saver
ls /Library/Screen\ Savers/ | grep .saver
[/code]

[b]With this one:[/b]

[code]
ls /Users/$user/Library/Screen\ Savers/ | grep .saver
ls /System/Library/Screen\ Savers/ | grep .saver
ls /System/Library/Screen\ Savers/ | grep .slideSaver
ls /System/Library/Screen\ Savers/ | grep .qtz
ls /Library/Screen\ Savers/ | grep .saver
[/code]



[ Reply to This | # ]