
In order to change the background at the given time you need the special
tools.  Basically you can use for such a purposes the cron or the at tasks. 
The more complicated case is to change the background at the sunrise and at
the sunset.  To achieve that it is required the program that counts the
times of the sunrise and the sunset.

The sunwait 20041208 by Daniel Risacher is such a tool.  You will find it on
www.risacher.org/sunwait site.

To compile and install it use the commands such as:

    cd sunwait-20041208
    make
    cp sunwait /usr/local/bin

The program requires latitudes and longitudes using decimal fractions
instead of minutes and seconds.  Let us take into consideration Wrocław,
Poland.  According to the Polish Wikipedia Wrocław coordinates are:
51°06′36″N and 17°01′20″E.

To calculate the latitude and the longitude of Wrocław use the following
formulas:

    51 + 6/60 + 36/3600 = 51.11
    17 + 1/60 + 20/3600 = 17.0222222222222

So the valid coordinates of Wrocław in the format accepted by sunwait are:
51.110000N and 17.022222E.

Let us assume that in the ~/.wmbackground directory there are three
wallpapers:

    wallpaper-black.png
    wallpaper-gray.png
    wallpaper-white.png

In such a case the following cron tasks:

    00 00 * * * /usr/local/bin/sunwait sun up -0:15:00 51.110000N 17.022222E ; wmsetbg $HOME/.wmbackground/wallpaper-gray.png
    00 00 * * * /usr/local/bin/sunwait sun up 0:15:00 51.110000N 17.022222E ; wmsetbg $HOME/.wmbackground/wallpaper-white.png
    00 00 * * * /usr/local/bin/sunwait sun down -0:15:00 51.110000N 17.022222E ; wmsetbg $HOME/.wmbackground/wallpaper-gray.png
    00 00 * * * /usr/local/bin/sunwait sun down 0:15:00 51.110000N 17.022222E ; wmsetbg $HOME/.wmbackground/wallpaper-black.png

change the wallpaper four times a day: 15 minutes before sunrise to gray, 15
minutes after sunrise to white, 15 minutes before sunset to gray, and 15
minutes after sunset to black.

The above solution is not perfect because the mentioned tasks are performed
at the defined time so after you run the machine you have to wait until the
program will display the valid wallpaper.

Fortunately the sunwait program started with the -p switch displays a lot of
data including the sunrise and the sunset times:

    sunwait -p 51.110000N 17.022222E | grep 'Sun rises'

    Sun rises 0601 CEST, sets 1944 CEST

So the commands:

    sunwait -p 51.110000N 17.022222E | grep 'Sun rises' | awk '{print $3}'
    sunwait -p 51.110000N 17.022222E | grep 'Sun rises' | awk '{print $6}'

display the valid sunrise and sunset times.

That feature is exploited by the background-changer script from the contrib
directory.

The configuration section of the script looks like:

    Latitude="51.110000N"
    Longitude="17.022222E"

    Black="$HOME/.wmbackground/wallpaper-black.png"
    Gray="$HOME/.wmbackground/wallpaper-gray.png"
    White="$HOME/.wmbackground/wallpaper-white.png"

    Gap="15 minutes"

    Sunwait="`which sunwait`"

The Latitude and Longitude are the coordinates of your location.  The Black,
Gray, and White are three wallpapers: dark, dim, and light.  The Gap is the
time before and after the sunset or the sunrise when it is the dawn or the
dusk.  The Sunwait is the path to the sunwait program.

If you will define the Gray wallpaper the background-changer script will
change the background four times a day:

    from 15 minutes before the sunrise to 15 minutes after the sunrise
    (during the dawn) to Gray,
    from 15 minutes after the sunrise to 15 minutes before the sunset
    (during the day) to White,
    from 15 minutes before the sunset to 15 minutes after the sunset (during
    the dusk) to Gray,
    from 15 minutes after the sunset to 15 minutes before the sunrise
    (during the night) to Black.

If the Gray wallpaper is not defined the background-changer script will
change the background two times a day:

    from the sunrise to the sunset (during the day) to White,
    from the sunset to the sunrise (during the night) to Black.

To use the background-changer script copy it to the /usr/local/bin directory
and define the following cron task:

    * * * * * runner=cron /usr/local/bin/background-changer

The runner variable can be equal "cron" or "at".  Use it if you run the
script with cron or at as in the above case.  The script started with such a
variable checks whether the display variable is defined and aborts if it is
not.  As a result it does not run wmsetbg program when you work in the
console mode and cron or at do not send you a message with the following
warning:

    wmsetbg(main(wmsetbg.c:1322)): fatal error: could not open display

In order to display the valid background at the Window Maker run put into
~/.xinitrc file the commad running the background-changer script before the
command that runs Window Maker:

    /usr/local/bin/background-changer
    wmaker

