How can I change wallpaper automatically?

Solution 1:

The script worked when I tested in GNOME SHELL 3.36.6

[admin@ADMIN ~]$ gnome-shell --version
GNOME Shell 3.36.6
[admin@ADMIN ~]$ 

Here is the modified content under my $HOME/.profile file.

# start my custom script for setting random background wallpapers
if [ -f "$HOME/wp.sh" ] ; then
    bash $HOME/wp.sh &
fi

Here is the modified content under my $HOME/wp.sh file.

#!/bin/bash
# script to set random background wallpapers on my GNOME desktop
# set base path
export wallpaper_path=/home/admin/Pictures
shopt -s nullglob
# store all the image file names in wallpapers array
wallpapers=(
    "$wallpaper_path"/*.jpg
    "$wallpaper_path"/*.jpeg
    "$wallpaper_path"/*.png
    "$wallpaper_path"/*.bmp
    "$wallpaper_path"/*.svg
)
# get array size
wallpapers_size=${#wallpapers[*]}

# set wallpapers in incremental order
index=0
while [ $index -lt $wallpapers_size ]
do
    gsettings set org.gnome.desktop.background picture-uri "${wallpapers[$index]}"
    # index is maxing out, so reset it
    if [ $(($index+1)) -eq $wallpapers_size ]
    then
        index=0
    else
        index=$(($index + 1))
    fi
    # keep the wallpaper for the specified time
    sleep 1m
done

Wallpapers changed at 1m interval as expected.