puflogh300X74.gif

Polarwave's OpenBSD
Tips and Tricks for Newbies

| Fluxbox Desktop |

| Home | Tips and Tricks | Links | News Feeds | Fun | Contact | Blog (Opens in New Page) |


Rotating Fluxbox Wallpaper

I don't mind having the same wallpaper on all four of my desktop workspaces,
but I do get tired of the same one all the time. It's easy enough for you to add
the following to your ~/.fluxbox/menu:

[submenu] (Wallpaper)
     [wallpapers] (/home/user/wallpaper( {feh --bg-center}
[end]
Then you can just hold your mouse over the menu entry and the entire list of all
the wallpapers will show up for you to choose from for fluxbox to load. There are
programs around you can install and use to do what I'm writing about here, such
as Fluxter and Fluxspace, and they're in the OpenBSD ports and packages. But,
there's another way to rotate wallpaper with just a script which you can add to
your menu and, if you want to do it automatically on a scheduled basis, by using
the script and a cronjob. The time between changes is arbitrary. I do mine daily,
but you may want to change yours more often or less. You can experiment with
the script as you see fit. The script searches a plaintext file with all the entries
numbered 1 through 31 using the date to set the right wallpaper file. Previously
I had been working on an idea where I needed a time value in my environment,
and it proved handy in this this project. In my ~/.kshrc I have the following:
TODAY=$(date ¦cut -c 9,10)
TODAYWP=~/bin/$(grep $TODAY ~/bin/mywalls.txt ¦cut -c 6-19)
export TODAY TODAYWP
If I type date without any extra switches, I get:
Tue Jul  1 00:09:57 CDT 2008
But, if I type date ¦cut -c 9,10 I get the following:
 1
Maybe you noticed the 1 is not lined up vertically with the blockquotes above.
There's a space in front of it, since the date was the first when I ran the command.
No zero is shown there. Doesn't affect the use of it, though, in the other value I
mentioned above, TODAYWP. When the script I'm going to show further on runs
it uses the same value terms as what I have in my .kshrc file, but gets its actual
values from the system time, not from the values in the environment from when
I first logged in. After all, I might have been logged in and running X for several
days which is quite often the case, and those values would be stale then. If I close
my X desktop but don't logout completely from the system, those stale values are
still there. I'll show later on how I refresh that value in the environment in my
.xsession file before I start X again. But first, here's the script I use, todaywp.sh,
to change the wallpaper:
#!/bin/sh
TODAY=$(date ¦cut -c 9,10)
TODAYWP=$(grep $TODAY ~/wallpaper/mywalls.txt ¦cut -c 6-23)

if ps -U dennyboy ¦grep -q X11R6;

then

     DISPLAY=:0.0 fbsetbg -c ~/wallpaper/$TODAYWP

else

     echo "Denny's not running X right now"

fi
If you look at the grep command above, you'll see a -q after it, so that when you
run it from the command line it won't echo on the screen. It won't show up in your
email either if you run the script from a cronjob. If you don't want to be emailed at
all when the cronjob runs, just put > /dev/null 2&>1 after the command in your
cronjob entry. I copied my favorite 31 wallpaper files to simple 4-letter names so it
would be easy using my script with cut and grep. The plaintext file mentioned above
which I call mywalls.txt looks like this:
01 - wpaa.jpg
02 - wpab.jpg
03 - wpac.jpg
04 - wpad.jpg
and so on all the way to 31.
My scheduled cronjob entry to change the wallpaper looks like this:
01     8     *     *     *     $HOME/bin/todaywp.sh > /dev/null 2>&1
Now, as I said before, you might close X but still be logged in. If you restart X
without logging out and logging back in, those old values are still there in your
environment. I fixed the problem in my .xsession like so:
. ~/./.kshrc
And in the next four lines, after the environment is refreshed, the wallpaper is set
using the TODAYWP value:
cat ~/.fluxbox/1sthalf > ~/.fluxbox/init
echo "session.screen0.rootCommand:    fbsetbg -c `env ¦grep TODAYWP`" ¦ \
cut -c 1-43,67-78 >> ~/.fluxbox/init
cat ~/.fluxbox/2ndhalf >> ~/.fluxbox/init
Before I started messing around with my old existing ~/.fluxbox/init file, I backed
it up to a different name. I took the first 46 lines above the wallpaper setting and
saved them in the file 1sthalf. I saved the 46 lines after the wallpaper setting to
the file 2ndhalf. As you see above, the init file gets overwritten each time you start
X. That's why you need to back up your original first. The > does the overwriting.
The right wallpaper file for the day is tacked on, or concatenated, below the first
half of the file using the double >> right redirection symbols. Then the second half
is concatenated below that, once again using using the double >> right redirection
symbols. Now the sytem contines starting X and processing whatever else is in the
.xsession file.

As happens so often with me, this whole thing was cooked up just to see if I could
accomplish it just using as many regular system utilities as I could without having
to rely on external third-party stuff, and to keep learning about shell scripting. An
exercise in learning, that's all. I'm sure it's probably easier using the other programs
spoken of earlier. I added their links again below here for easy quick reference.

Cheers!

Related Links:
Fluxbox
Fluxspace
Fluxter

Back to Tips and Tricks
Home

Delicious Bookmark this on Delicious

No affiliation between this site and the OpenBSD project exists or is implied.

valid-html401.png