![]() |
Understudy.net/orgOk you have made it this far.You obviously must be bored and have nothing better to do with your life. |
![]() |
[Previous entry: "Couple more small articles for Chucktips"] [Main Index] [Next entry: "A server monitor script"]
08/28/2004 Archived Entry: "Howto: Change backgrounds in WindowMaker with a script"
I have found a way to change the background in WindowMaker. I have modified the script I found to work with FreeBSD (4.10). This is the second script I have ever really done anything with so go easy on me.
I found the original script on Unixtips.org. The script was written for Linux. Also the original script didn't change the background color at all. I want to thank vlaad at #WindowMaker (irc.openirc.net) along with Per Hedeland on comp.unix.backgroundsd.freebsd.misc for the help with DISPLAY issue.
Vlaad also wrote the background changing portion of the script. Lesi at #freebsd (irc.freenode.net) who helped me comment the script, and if I forgot anyone I apologize.
Everything here must be done by the user (not root) who is running X (startx).
Here is the script:
#!/usr/bin/perl #Set perl path,be sure to use the correct path here
# This is a perl script for use with wmsetbg.
# This allows wmsetbg to run as a cron job.
# Portions of this script were found on http://unixtips.org/articles/background.php3
# The orginal script was written by Scott Parish
# I have modified this for use with FreeBSD (4.10-STABLE) with XFree86 4.4
# Use your own location for Background images
# Modified by Brendhan Horne
# Get a list of all the backgrounds
opendir DIRECTORY, '/usr/X11R6/share/WindowMaker/Backgrounds/Heather/';
@images = readdir DIRECTORY;
closedir DIRECTORY;
# Sets the location of X authority file.
# If you are in X comment out this line.
# You can not run this as a cron job if you comment this line
$ENV{XAUTHORITY} = "/usr/home/bhorne/.Xauthority";
# Sets DISPLAY so that the wmsetbg knows where to change the background.
# If you are in X comment out this line.
# You can not run this as a cron job if you comment this line
$ENV{DISPLAY} = ":0.0";
# Opens rgb color-name database, used later for background
# Your location may be different.
open RGB, "/usr/X11R6/lib/X11/rgb.txt";
# Give an identity to array of color names, used for background
my @bgs;
# the next lines are what is used to create a background color. While in RGB,
# ignore comments, choose the color by name , and place it to the background
while(
next if m/^!/;
(undef, undef, undef, $color) = split;
push @bgs, $color;
}
close RGB;
# Define prop for the -p switch used by wmsetbg. mpixmap is used to max scale and
# aspect ratio of the image. The directory where the image array is chosen from
# is listed. The rand is used for random image choices. The @bgs chooses the
# backgrounds color
my $prop = "(mpixmap,/usr/X11R6/share/WindowMaker/Backgrounds/Heather/$images[int(rand @images)+2],$bgs[int(rand @bgs)+2])";
#This following line runs wmsetbg -p /usr/share/WindowMaker/Backgrounds/Heather/randomimage
system ('/usr/X11R6/bin/wmsetbg','-p',"$prop");
#end of script
I saved the script as background.pl and did a chmod +x to make it an executable. I checked the PATH in my shell *rc file and moved it to /usr/local/bin (you may have to be root to move it). I then created cron.txt file and placed the following lines in my cron.txt file:
# this is the crontab file for bhorne
# this changes the backgroud in windowsmaker every hour
0 * * * * /usr/local/bin/background.pl
# end of file
Exit and save changes. Then at the command line:
crontab cron.txt
this will cause the background to change every hour. You can check at the command line by :
crontab -l
That's a lower case L not a number 1.
You will see the contents of your cron.txt file. If you see those lines the script is set. Enjoy.