This blog embraces totally the foundamentals of the Open Source Spirit and Soul. Hence all material founded here is free and the user may read, copy, manipulate, reproduce it all, without limitations of any kind, no copyright allowed here!
Nevertheless the author will appreciate if the user will cite him, when using his scripts, as a recognition of his work.
Knowledge is the prime right of umanity and has to be protected and shared with every possible means.
abidibo.

Tuesday, November 30, 2010

HowTo randomly change fluxbox wallpaper every n minutes

Some weeks ago' I've discovered this fantastic WM (Windows Manager), thanks to Gentoo/Sabayon + GNOME dbus sessions problems with my Imac. I desired so much to learn something about portage and the gentoo world that I accepted going on without gnome. Fortunatelly.Fluxbox is a very light and high configurable WM for X server, super super fast and with all such things one need to work fine (alt-tab to move around opened windows, a nice bar showing opened applications and so on). It doesn't have icons by default, but has an amazing menu totally and easily configurable showing up when clicking on the desktop.
Here I want to show how is possible to set a cronjob task that changes randomly the desktop wallpaper every 5 minutes.FIRST: install fehfeh is a fast, lightweight image viewer, supporting many image formats that we'll use to show the wallpaper. So

$sudo emerge feh

SECOND: try it out
Open the ~/.fulxbox/menu file and add some wallpaper voices, like

fbsetbg is a wrapper that searches for a image viewer in order to set the fulxbox background (in our case it'll use feh, but other programs may be used).
Now clicking on the desktop and selecting a wallpaper voice from the menu should change our fluxbox wallpaper, if not maybe there were some problems during the installation of feh, try solving them and continue. THIRD: make a script that changes the background randomly
So put all the desired images inside a folder and then copy this code in a file that we'll call chgWallpaper.sh

Why we export the DISPLAY variable? Well, we always have to remember that the processes started by cron have no (or almost no) normal environment setup, and our script require this variable. So from terminal as normal user run

echo $DISPLAY

take the result and put it in place of :0.0
The second line of the script launches fbsetbg passing it one (tail -1) file randomly (sort -R) taken from the ~/Wallpapers directory (ls).FOURTH: schedule the script with crontab
Now we have to schedule this script. My system has vixie-cron, many others uses crond, it's the same. We want to schedule the script as normal user (abidibo in my case), so

$sudo crontab -u abidibo -e

This commands opens your favourite editor, now we have to insert the job:

*/5 * * * * /bin/bash /home/abidibo/Scripts/chgWallpaper.sh

This way the script is run every 5 minutes. Now we save the file and exit and the new crontab is installed. We wait 5 minutes and our desktop background should change, if not go on reading.TROUBLESHOOTING
If this doesn't work may be it happens something like what happened to me.
Read your system log file, in my case