Gentoo Wiki ArchivesGentoo Wiki

Make_your_background_rotate_with_feh

First of all get all the images you want into a folder, I used ~/Images, then you rename all of these images to 1,2,3,.. etc. These images must all have the same file extension too.

Then add this to the top of your ~/.xinitrc:

File: ~/.xinitrc
~/bin/rand.sh

Then create ~/bin/rand.sh and add this to it:

File: ~/bin/rand.sh
#!/bin/bash
#Created By Andy Etches
LOBOUND=1
HIBOUND=20
RANDMAX=32767
BINUMBER=$(( $LOBOUND + ($HIBOUND * $RANDOM) / ($RANDMAX + 1) ))
feh --bg-scale /home/andy/Images/$BINUMBER.jpg

Make sure that you set HIBOUND to the number of the last file, not one higher than it!

An extension of this script follows:

File: ~/bin/rand_wallpaper.sh
#!/bin/bash
#Random image wallpaper selector
#ArrnekTornal <at> gmail.com
#Script inspired by code by Andy Etches from the Gentoo Wiki at:
#    [[HOWTO_Openbox]]

IMAGE_DIR="~/wallpapers"

ls "$IMAGE_DIR" > images.tmp

#Redirect input to come from themes.tmp and save as file descriptor 2
exec 7< images.tmp
exec <&7

#Declare an array to hold each image name in the directory IMAGE_DIR
declare -a IMAGES

#Read each image file name from the images.tmp file
i=0
while read -u 7 CUR_IMAGE
do
    #Assign the next name to the next position in the array
    IMAGES[${i}]="${CUR_IMAGE}"

    #Increment array index position
    ((at i++))
done

#Close file descriptor 7
exec 7<&-

#Delete the temporary themes list
rm -f images.tmp

MAX_INDEX=$((${#IMAGES[@]}))

#Currently an array of images names exists
#Now set the desktop image to a random image from this array

#Get a random number from 0-MAX_INDEX
IMAGE_INDEX=$(( $RANDOM % $MAX_INDEX ))

#Now set the corresponding image
feh --bg-scale "${IMAGE_DIR}/${IMAGES[${IMAGE_INDEX}]}"

The directory ~/wallpapers contains all the images desired to be potentially displayed. Running the script randomly selects one of these images and sets it as the desktop image.

Retrieved from "http://www.gentoo-wiki.info/Make_your_background_rotate_with_feh"

Last modified: Sat, 06 Sep 2008 09:28:00 +1000 Hits: 4,731

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.