A new script to change the wallpaper. What it does is grabs all the images from your wallpaper folder including sub directories. Then it creates a list and saves it to your hard disk. Then it randomly chooses a WP from the list. Whenever you run it checks to see if the number images in your list matches the number of images in your WP folder, if not it saves the updated list to disk.
Code:
#!/bin/bash
# Set your folder with the pics
picsfolder="/media/main/Wallpapers/"
#Set the Path to the Wallpaper list will be created
wplistpath="/home/username/wplist.txt"
#go to the picture directory
cd "$picsfolder"
#load the list of pics to a variable
wpDirList=`(find . -regex ".*\(jpg\|jpeg\|gif\|png\|svg\)$" -type f)`
#find the number of pics in the WP dir based on the extension
numberOfPicsDir=`echo "$wpDirList" | wc -l`
# Count number of pics in the Wallpaper list by counting number of lines.
numberOfPicsList=0 #initial lise
#check if the wallpaperlist Exists
if [[ -e "$wplistpath" ]]
then
numberOfPicsList=$(wc -l < "$wplistpath")
else
echo "WP list does not exist"
fi
# inform the user
echo $numberOfPicsDir" --- "$numberOfPicsList
# if they don't match rewrite the wallpaper list
# this if can be removed and the list can be saved every time
if [ $numberOfPicsDir -ne $numberOfPicsList ]
then
#save the list to disk
echo -n "$wpDirList" > "$wplistpath"
fi
# Find a random line number in the wallpaper list
r=$((RANDOM % numberOfPicsDir + 1)) # Random number from 1..n.
# print what the line number is
picPath=`sed -n "$r{p;q;}" "$wplistpath"` # Print the r'th line.
wpPath="${picsfolder}${picPath#./}" # #./ crops that substring but it doesn't matter if it left there
echo "$wpPath"
#set the wallpaper in Gnome Config Editor
gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$wpPath"
Preferably you should break the script into two scripts one that creates the wallpaper list and this should be scheduled to run once a week and the other script that will pick an image from the wallpaper list which can be run every 5,10,15,60 mins etc.
That said I am running this on a list of 3000+ images without problems.
Here is a link to a good Bash FAQ/Tutorial.
http://wooledge.org/mywiki/BashFAQ?a...direct=BashFaq
Bookmarks