Tuesday, August 11, 2009

Timed Random Wallpapers in Openbox

Finally got a perfect random wallpaper set-up in Openbox! This set-up starts my ~/wallpaper.sh script when I log into Openbox and finds a new (random) wallpaper, every six minutes, from my ~/photos-openbox directory.


~/wallpaper-loop.sh

#!/bin/bash

while [ 1 ]
do
/home/steve/wallpaper.sh
sleep 6m
done


~/wallpaper.sh

#!/bin/bash

WALLPAPERS="$HOME/photos-openbox"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[*]}
SHOW=$(( $RANDOM % $RANGE ))

feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}


~/.config/openbox/autostart.sh

# Programs to launch at startup

#numlock
numlockx &

#screensaver
xscreensaver &

# Programs that will run after Openbox has started
(sleep 2 && fbpanel) &

#My wallpaper (random wallpaper script - calls wallpaper.sh)
(sleep 3 && /home/steve/wallpaper-loop.sh) &


Very, very nice! Thanks to frisil at the MepisLovers forums for the tip on the infinite loop. I'd spent a lot of time trying to find a way to get a random wallpapers in Openbox; the wallpaper.sh script by itself did this, but adding a line for it in the autostart.sh script only gave me a new wallpaper each time I logged into Openbox. This set-up works about as well as KDE's automatic background changer or GNOME's wallpaper-tray.

2 comments:

Chad Bergeron said...

Found this script. Great! Except it won't work with files that have spaces in their names. Thought I'd warn people that they'll need to rename their files.

MALsPa said...

Chad, thanks for your comment! I didn't think about that situation -- I don't use spaces in any of my file names, got out of that habit some time ago -- but it's a good thing to know!