Automatic wallpaper changing script for lxde

Hello!

Yesterday, I was looking for a script to automaticly change my lxde wallpaper, and after a long searching I found a nice way to do that. I worte these 2 scripts.

The first script picks a random wallpaper from your wallpapers directory and sets it as wallpaper.

The second script runs the first script every specified time.

Put these 2 scripts in /usr/bin/

Save this one as /usr/bin/rotator

#!/bin/bash

picturesPath=/usr/share/backgrounds #Your wallpapers folder

#IFS="$(printf '\n\t')"
#allFiles=( $(find "$picturesPath" -maxdepth 1 -type f) )

allFiles=()
for f in $picturesPath/*; do
    if [ -f "$f" ]
    then
            allFiles[${#allFiles[@]}]="$f"
    fi
done

allFilesCount=${#allFiles[*]}

if [ ${allFilesCount} -eq 0 ]
then
    exit 1
fi

selectedFileIdx=$[ ( $RANDOM % ${allFilesCount} ) ]
selectedFile=${allFiles[$selectedFileIdx]}

if  [ -f "$selectedFile"  ]
then
    echo "$selectedFile"
     sleep 1s #increase if problems
    pcmanfm --set-wallpaper="$selectedFile" #you can change this command with your desktop manager's one
fi

after saving, run “sudo chmod +x /usr/bin/rotator”

And save this one as /usr/bin/autowall

while [ 1 -eq 1 ]; do

   rotator
   sleep 15m #Change wallpaper interval, This is 15 minutes
done

then run “sudo chmod +x /usr/bin/autowall”

After that, add this line to your ~/.config/lxsession/LXDE/autostart to automaticly run the script at startup.

@autowall

cheers!