Re: Random background images? How?



I think Gnome/Sawfish is the limited because you can't assign different images to different workspaces. I also think nautilus is bad because it forces you to let it control your background if you want icons. How cruel.

I use the Window Maker window manager, and it allows me what I want. The wmsetbg program in WindowMaker sets backgrounds, either for the default window or for specific workspaces.

I have a script that randomly changes backgrounds, it is written in perl, and I've attached it for you. I call that script in a shell script:

#!/bin/sh
export PATH=/usr/local/bin:$PATH
/home/pj/bin/pjbackground -D :1.0 -d /usr/share/Backgrounds
/home/pj/bin/pjbackground -D :1.0 -w 2 -d /usr/share/Backgrounds/sea
/home/pj/bin/pjbackground -D :1.0 -w 3 -d /usr/share/Backgrounds/beach

-D is the display. Most systems only have display 0.0, but mine has 1.0 as well. You probably should put 0.0 there.

if you don't add a -w flag, it changes the background of the root workspaces. That is the default background, the one that shows on all workspaces unless you say otherwise.

If you add a -w flag, it changes that background only.

-d is the flag you use to tell it where your pictures are. It searches throughout that directory structure.

If you want this to change on a schedule, use a cron job. I do, it is fine.


stan wrote:
I'm using Gnoe with Sawfish as my window manager.

Given a directory containg a number of JPEG images, is it possible to have
a random one selected fro my background image each time I log in?

If so, how?





--
Paul E. Johnson                       email: pauljohn ukans edu
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700
#!/usr/bin/perl
use File::Find; #to get all files under mainDir
use Getopt::Std;  # command line processing

getopts("w:d:D:")|| die "Invalid argument\n";

if ($opt_w =~ /\D/) { die "w is not a digit";}

@images = ();

if ($opt_D) {
	$DIS = $opt_D;
}
else{
#	$DIS = ":0.0"
	$DIS = $DISPLAY
}

if ( $opt_w ) {
    $workspace = $opt_w-1;
}


sub process_file{
    $filename = $File::Find::name;
    if ( -f $filename ){
	push(@images, $filename);
    }
}


if ( $opt_d ) {
	$basedir = $opt_d;
    }
else{
   $basedir = "$ENV{HOME}/GNUstep/Library/WindowMaker/Backgrounds";
} 


find(\&process_file, $basedir);

srand;
$index=int(rand(@images));

if ($opt_w){
print "\n On disply '$DIS' workspace $opt_w, the background image is now @images[$index] \n";
exec '/usr/bin/wmsetbg','-display',"$DIS",'-a','-u','-w',"$workspace",' ', $images[$index];
}
else{
print "\n On display $DIS, The background image of the root window is @images[$index] \n";
exec '/usr/bin/wmsetbg','-display',"$DIS",'-a','-u',' ', $images[$index];
}


pjbackgrounds-README
Paul Johnson Aug.27, 2000

I am a Gnome user, but vigorously resist the pressure to use
Sawfish. One reason is the pleasant workspace picture capability of
Window Maker and wmsetbg.  Yesterday I worked on a perl script which
can change the background, either for the default window or a
particular workspace, and it will randomly select an image from a
specified directory, OR ANY OF ITS SUBDIRECTORIES.  If no directory is
specified, it is taken from ~/GNUstep/Library/WindowMaker/Backgrounds.

I am modestly calling the perl program "pjbackground" and I've put it
in my web site http://lark.cc.ukans.edu/~pauljohn/WindowManagers.
There is pjbackground, a readme file, and there is a file called
pjbackground-shell that you can call from cron to automate this.

Use it like this:

1. with no command line options: changes root window background to a
picture anywhere in ~/GNUstep/Library/WindowMaker/Backgrounds.
 
$ pjbackground

You should see output like so:

 The background image of the root window is
/home/pauljohn/GNUstep/Library/WindowMaker/Backgrounds/sdc99_0659_yosemite_ss.jpg

2. specify the workspace, use the default image directory. (note, I'm
using the workspace number on the clip, not the internal workspace
number, which is one smaller).

$ pjbackground -w4
 On workspace 4, the background image is now
/home/pauljohn/GNUstep/Library/WindowMaker/Backgrounds/sdcss_089_snow_leopard.jpg

3. Specify a root image directory and it will choose a random one for you:

$ pjbackground -w4 -d /usr/local/share/Backgrounds
 Here is /usr/local/share/Backgrounds/canyon.jpg 


When I tried to run this program under cron, I ran into environment
problems, and learned that cron runs without much environment. So
instead of scheduling pjbackground directly, I schedule a shell script
"pjbackground-shell" and it gets the job done. I just added this entry
with "crontab -e"

0 * * * * /home/pauljohn/bin/pjbackground-shell

to change the picture at the top of the hour in, for example,
workspace 4.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]