|
|
Version II of this script
I have taken Kevin's script and made a bunch of tweaks and changes to have it be a bit more general purpose. I've also added some comments and unwrapped the code to be a bit more readable:
#!/usr/bin/perl -w
# Written by KevinL
# with minor tweaks by Dave Taylor <taylor@intuitive.com>
#
# Note: this is best run by cron every day, so that your images are
# constantly shuffling around. To do that, you'll want to make sure
# that this program switches to the correct directory, which is most
# easily done by including the following line (with the directory
# specification changed to your own Screen Saver Images directory,
# of course!):
# chdir("/Users/kevin/Pictures/Desktop Pictures") || die "I can't chdir";
srand; # initialize random number package
foreach $file (<*.[jJ][pP][gG]>) {
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, $_);
}
}
Comments??
Btw, how do you avoid having code listings in a <PRE> double-spaced? I have post mode = HTML Formatted, but it's still adding <br> after each line. Blech.
Version II of this script
Given Kevin's explanation of the problem with backslashing the underscore in the substitution operator I'll assume that you've done that (and had it promptly stripped by the formatter...) |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.07 seconds |
|