Tuesday, April 6, 2010

Ubuntu / Gnome change your wallpaper every 10 seconds

Ok so assuming you have a folder named Wallpaper in your home directory which contains numbered .jpg's(in my case 385) you can use this to change your wallpaper every 10 seconds. You can adjust how often it changes by changing the sleep number on the 5th line of the script and you can adjust the number of wallpapers you have on the sixth line of the script by changing the number 385. I originally had made this as a cron job rather than a constantly running perl job which I run in screen (screen perl wallpaper.pl...then ctrl + a + d). However I was having some trouble getting it to work with cron, and the outside sources I used to help figure this out where at a loss so here it is.


#/usr/bin/perl
use strict;
use warnings;
while(1){
sleep(10);
my $numberW = int(rand(385));
print $numberW;
my $wallpaper = "gconftool-2 -t string -s /desktop/gnome/background/picture_filename /home/lane/Wallpaper/".$numberW.".jpg";
system($wallpaper);
}


Now you may wonder how you get neatly numbered wallpapers. Well I wrote a script for that as well and it works as long as none of the wallpapers are already named as numbers already. Remember to change the @files dir to the directory where the pictures already exist non-numbered, and to put the $newfile directory where you want the new files to go. It is not advisable that these be the same place.


#!/usr/bin/perl -w
use strict;
use warnings;
my @files;
my $it = "207";
print $it;
@files = ;
my $counts;
my $newfile;
my $file_number = "0";

while(1){
foreach (@files) {
my $file_regex = qr!(\d+\.jpg)!s;
if ($file_regex =~ @files) {
$counts = $counts + 1;
print $counts;
if ($counts == scalar @files) {
print "fuck you";
}
if ( $counts == scalar @files ) {
exit();
}
}
my $loopy = "1";
while($loopy){
my $file_regex = qr!(\d+\.jpg)!s;
if ($file_regex !~ @files) {
$newfile = '/Users/lane/Downloads/tat/ta2/'.$it.".jpg";
rename($files[$file_number], $newfile );
++$it;
++$file_number;
if( ! -e $newfile){
$loopy = "0";
exit();
}

}
}
}

No comments: