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!

Advertisements

6 thoughts on “Automatic wallpaper changing script for lxde

  1. There is a simpler way:
    —————————-
    #!/bin/bash
    DIR=”/home/wallpapers”
    while true; do
    pcmanfm –set-wallpaper=”$(find $DIR -type f | shuf -n1)”
    sleep 3h
    done
    —————————-
    it works for all files and folders in folder $DIR recursively

  2. That was Absolutely one on the best first time runners. It was totally kick ass once I directed the folder the my personal wallpaper folder. Absolutely works, I struggled with XLM files and other scripts, I do not know how how the write or interpret but yours was the best kick ass. I read the code and got an understanding of what it is doing. I apologize if other have issues. I using Linux mint 16 lxde as one of the desktops. My GF uses KDE.. I wanted a Wallpaper Changer too but I had to go to this and this makes it so my TV does not go into saver mode during a movie. Thank a bunch for you contribution. I hope I can help someone someday like you did.

Leave a Reply :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s