Random screensaver image rotation script

Jan 08, '02 12:01:06AM

Contributed by: kevinl

I love using my own pictures in the built in screensaver, but I got sick of seeing the same order of the pictures. So, I wrote the following perl script to attach a pseudorandom number before the file names in the selected folder. The script assumes it is being run from inside a folder with all your images (no subfolders) that are named *.jpg -- it checks to see if they have a two-digit number, underscore prefix, and adds them if necessary. Otherwise it changes the number to a new value. Run as often as you like or have cron do it.

Read the rest of the article for the script...

#! /usr/bin/perl -w

srand;
foreach $file () {
if ($file !~ /^[0-9]+_/ ) {$pref=int rand(100); $new=$pref."_".$file; rename ($file, $new);}
elsif ($file =~ /^[0-9]+_/) {$pref=int rand(100); $_=$file; s/[0-9]+_/$pref_/; rename ($file, $_);}
}
[Editor's note: Any typos in the above are probably my fault ... let me know if something appears incorrect as I have not tested this myself!]

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020108000106420