I thought I would just post this for anyone that is interested in a lightweight wallpaper changer. I did not write it–the thanks go to the author in the script. This is for the Gnome3 DE–try it in others at your own risk…Enjoy! NOTE: you can try the first script, dalto recommended modifications to allow tolerance in the script–that is the second script below. I would recomend his modification–I am currently using it.
Script Start:
#!/bin/bash
#
# WallpaperChanger.sh
# Copyright 2014 Michele Bonazza michele@michelebonazza.com
#
# A simple script to automatically change your wallpaper in Gnome.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
WALLPAPERS_FOLDER=/home/yourhome/yourwallpaperfolder
REFRESH_INTERVAL=$((5 * 60)) # change every 5 minutes
MODE="stretched" # one between none, centered, wallpaper, scaled, stretched, zoom, spanned
# Changes the desktop background, and moves it to the "shown" folder so that it's
# not shown again before all wallpapers in the folder have been used.
# arg1 the file name of the file to be set as new background; must be in the
# current folder
function change_wallpaper() {
mv $1 shown
gsettings set org.gnome.desktop.background picture-uri file://$WALLPAPERS_FOLDER/shown/$1
gsettings set org.gnome.desktop.background picture-options $MODE
}
# Echoes the next wallpaper to be set, picked at random among images in the
# configured folder
function get_next_wallpaper() {
find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg"| shuf -n 1
}
mkdir -p $WALLPAPERS_FOLDER/shown
cd $WALLPAPERS_FOLDER
while true; do
NEXT_WP=$(get_next_wallpaper)
# have we used all wallpapers?
if [[ "$NEXT_WP" == "" ]]; then
# yes, chdir to shown, and move them all back to the parent folder
cd shown
# move them to parent folder
find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg" | xargs mv -t ..
cd ..
# check again
NEXT_WP=$(get_next_wallpaper)
if [[ "$NEXT_WP" == "" ]]; then
echo "no wallpapers found in $WALLPAPERS_FOLDER, will check again in $REFRESH_INTERVAL seconds..."
sleep $REFRESH_INTERVAL
continue
fi
fi
echo "changing background to $NEXT_WP"
change_wallpaper $NEXT_WP
sleep $REFRESH_INTERVAL
done
End Script:
As you can see, it uses your selected folder & creates a “shown” folder inside of it. Then it uses a sudo-random select of the remaining wallpapers in the folder.
These 3 functions define its operation:
WALLPAPERS_FOLDER=/home/yourhome/yourwallpaperfolder
REFRESH_INTERVAL=$((5 * 60)) # change every 5 minutes
MODE=“stretched” # one between none, centered, wallpaper, scaled, stretched, zoom, spanned
I’ve used this from when it was offered & am very happy with the operation. Just put the script in your /home, chmod it & create a startup for it & you are good to go.
So, as noted below—make sure there is NO whitespace in the filenames. I have used underscores if there needs to be seperation between words in the wallpaper name. Best practice is to condense the name with no “blanks” between words.