Random wallpaper changer script

I couldn’t decide which high-res picture to set as my desktop background and I wanted to see all images from a specific directory from time to time, so I wrote this script that helps me to chose which sportscar to look at. In fact the brand is always the same ^_^

randWallpaper.sh takes a directory with pictures as a parameter.
It will then read those files in an array and set one of those files as your background wallpaper randomly.

Dependencies : hsetroot

randWallpaper.sh :

#!/bin/bash
IFS=$'\n'
NUM=0
for NAME in $(find $1 -type f)
do
	array[$NUM]=$NAME
	((NUM++))
done
RAND=$RANDOM
let "RAND %= $NUM"

echo ${array[$RAND]}
hsetroot -center ${array[$RAND]}

Usage in OpenBox:
Edit your

~/.config/openbox/autostart.sh

and add this line to it :

randWallpaper.sh path_to_folder_with_images

On every start of X you will have one of the images in that folder set as your background.

Download randWallpaper.sh

Cheers.

Leave a Reply