An automatic wall paper changer for wmakerAn automatic wall paper changer for wmaker

I recently switched to using Window Maker on PC-BSD, one of my favorite window managers actually. But it does have a few dis advantages over KDE when it comes to session management…

I went though my large wall papers collection and found several that I would like to use, the WMaker theme I have set is a dark one.

Terry@Dixie$ ls ~/Pictures/Wall_Papers|wc -l 6:38
Terry@Dixie$ ls ~/GNUstep/Library/WindowMaker/Backgrounds|wc -l 6:40
Terry@Dixie$ 6:40

Many didn’t scale right and I don’t know of any batch image scaler, so I had my shell open each in kolour paint so I could do this. Using a graphical file manager I would have to double click each file at the least level of effort… With the shell, it was simple loop in my backgrounds directory:

for i in `ls`
kolourpaint $i

This opened kolourpaint to a file, allowing me to do a quick ctrl+e and set it to smooth scale it to 1280×800 to match my LCD’s native resolution. And then to ctrl+s save it, X out of it and volia, kolourpaint would start again with another file as it continued through the loop.

Having done this, I was thinking how to I get it to change after awhile? I thought about a symlink that would be changed to a different wall paper every now and then, tested it no go. Then I found wmsetbg and the -s (-scale) option, so yeah I wasted my time scaling them all lol.

So I removed them and made symlinks to the original files in my wall papers directory:

for i in `ls`                                                 6:40
ln -hfs /home/Terry/Pictures/Wall_Papers/$i /home/Terry/GNUstep/Library/WindowMaker/Backgrounds/$i

Like I am going to stand here and create 50++ shortcuts myself? NO WAY!

After that I set to look into hooking up a shell script that could run in the background and change the wall paper for me. I figured that I would want some thing acline to the sleep() function out of unistd.h but I didn’t really want to use a C program or any other programming language to do it. Because while looping over the directory in C might be faster then /bin/sh by the time the compiler tried to optimize it. Having to invoke a shell for every call to system() (for running wmsetbg) would probably be a bit wasteful. At least in a shell script, there should be no need to create a new /bin/sh process on each pass. Didn’t find a built in shell command for it but /bin/sleep works fine, so I wrote the following script to change my wall paper every 10 minutes:

# A simple automatic wall paper changer for window maker.

while (true)
for p in `/bin/ls /home/Terry/GNUstep/Library/WindowMaker/Backgrounds/`
wmsetbg -u -s $p
sleep 600

And to run it on window makers start up, I added this line to my ~/GNUstep/Library/WindowMaker/autostart file:

/usr/home/Terry/sh/setbg &

and Hooah ^_^

And here is a python script that displays it in a random order,


import commands
import os
import random
import time

li = os.listdir('/home/Terry/GNUstep/Library/WindowMaker/Backgrounds/')

while (True):
commands.getoutput('/usr/local/bin/wmsetbg -u -s %s' % (x))

Hmm, I wonder if I could do this on Windows XP to,under explorer of course hehe.