Wisp558
August 13th, 2010, 12:22 AM
So I got bored today, and decided that my desktop just wasn't interesting enough. So I wrote this script. It'll cycle through random .png and .jpg images in a directory. Here's the script.
#!/bin/bash
DIR=/home/wisp/Wallpapers
FLOOR=1
RANGE=`ls -1 "$DIR"/*.jpg "$DIR"/*.png | wc | awk '// {print $1}'`
number=0
while [ 1 -eq 1 ]; do
number=$RANDOM
while [ "$number" -le $FLOOR ]; do
number=$RANDOM
done
let "number %= $RANGE" # Scales $number down within $RANGE.
COUNTER=1
for X in "$DIR"/*.jpg "$DIR"/*.png
do
if [ $number -eq $COUNTER ]; then
feh --bg-scale "$X"
fi
COUNTER=$(($COUNTER+1))
done
COUNTER=1
sleep 2m
done
The observant will note that I use feh to change the background. If you use the standard GNOME desktop, you will need to replace
feh --bg-scale "$X"
with
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$X"
You will also need to change $DIR to wherever your wallpapers are, and you can change the 'sleep 2m' line to whatever you feel like keeping your wallpapers for.
To run it, just copy the code into a text file, name it, say, wallpaperrandomizer.sh. Then you just need to run chmod +x wallpaperrandomizer.sh, and run the file. ( ./wallpaperrandomizer.sh & disown )
Though it doesn't do recursive scanning, this script will tolerate spaces! Neat!
Enjoy.
#!/bin/bash
DIR=/home/wisp/Wallpapers
FLOOR=1
RANGE=`ls -1 "$DIR"/*.jpg "$DIR"/*.png | wc | awk '// {print $1}'`
number=0
while [ 1 -eq 1 ]; do
number=$RANDOM
while [ "$number" -le $FLOOR ]; do
number=$RANDOM
done
let "number %= $RANGE" # Scales $number down within $RANGE.
COUNTER=1
for X in "$DIR"/*.jpg "$DIR"/*.png
do
if [ $number -eq $COUNTER ]; then
feh --bg-scale "$X"
fi
COUNTER=$(($COUNTER+1))
done
COUNTER=1
sleep 2m
done
The observant will note that I use feh to change the background. If you use the standard GNOME desktop, you will need to replace
feh --bg-scale "$X"
with
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$X"
You will also need to change $DIR to wherever your wallpapers are, and you can change the 'sleep 2m' line to whatever you feel like keeping your wallpapers for.
To run it, just copy the code into a text file, name it, say, wallpaperrandomizer.sh. Then you just need to run chmod +x wallpaperrandomizer.sh, and run the file. ( ./wallpaperrandomizer.sh & disown )
Though it doesn't do recursive scanning, this script will tolerate spaces! Neat!
Enjoy.