Rotate your wallpapers with a command

I was watching a couple of youtube reviews, and for most of them only a few wallpapers are ever shown, which made me wonder: how hard is it to rotate the wallpapers?

Turns out, it’s not really that hard:

while true; do
    find /usr/share/backgrounds/ -type f | while read B; do
        gsettings set org.mate.background picture-filename $B;
        sleep 15;
    done;
done;

You can copy that right up in your terminal and zoo!

3 Likes

Feature Request :grin:

Could you add not a GUI, but a UI? With a way to select the path to whatever folder and maybe add a adjustable timer?

Thanks a lot to a fine code example. :slight_smile:

I made it into a script.

I ran it from a console.

Can I still exit out of the console and have the backgrounds still rotate ?

1 Like

So an UI is kind of stretching the limits of Zenity, I can't find a way to ask the two informations in the same dialog.

#! /bin/bash
BGDIR=`zenity --file-selection --directory  --filename=/usr/share/backgrounds --title="Select Wallpaper Directory"`
INTERVAL=`zenity --scale --title "Select interval in seconds" --value=15 --min-value=5`
while true; do
    find $BGDIR -type f | while read B; do
        gsettings set org.mate.background picture-filename $B;
        sleep $INTERVAL;
    done;
done;

@fixit7 if you launch your script with an ampersand at the end you should be able to close the terminal.

script.sh &

1 Like

#Excellent :slight_smile:

I will use this in place of Variety.

Thanks

###Update

Been on all night and glitch free.

Simple and effective just like it should be :+1:

1 Like

Here’s a small improvement.

[code]#!/bin/bash

BGDIR="$(zenity --file-selection --directory
–file-filter=“Image Files (*.jpg *. JPG *.jpeg *.JPEG *.png *.PNG *.gif *.GIF *.bmp *.BMP) |
*.jpg *. JPG *.jpeg *.JPEG *.png *.PNG *.gif *.GIF .bmp .BMP"
–file-filter="All Files (
.
)| .” --window-icon=“gtk-folder”
–filename=/usr/share/backgrounds/ --title=“Select Wallpaper Directory”)"

Quit if the BGDIR isn’t set (Cancel is clicked)

[[ -z “$BGDIR” ]] && exit 0

INTERVAL=$(zenity --scale --text=“Select the interval between\nthe wallpaper change event (in seconds)”
–title=“Select interval in seconds” --value=15 --min-value=5 --window-icon=“gtk-panel-clock”)

Quit if the INTERVAL isn’t set

[[ -z “$INTERVAL” ]] && exit 0

while : ; do
find “$BGDIR” -type f -iname *.gif -o -iname *.jpg
-o -iname *.png -o -iname *.jpeg -o -iname *.bmp
-exec gsettings set org.mate.background picture-filename {} ; -exec sleep $INTERVAL ;
done;[/code]
Nothing much can be done with zenity. Maybe, a set of predefined values like 5 minutes, 15 minutes, 30 minutes, 1 hour, 2 hours, 3 hours and custom. A li’l bit of complication can’t hurt. :wink:

[code]#!/bin/bash

BGDIR="$(zenity --file-selection --directory
–file-filter=“Image Files (*.jpg *. JPG *.jpeg *.JPEG *.png *.PNG *.gif *.GIF *.bmp *.BMP) |
*.jpg *. JPG *.jpeg *.JPEG *.png *.PNG *.gif *.GIF .bmp .BMP"
–file-filter="All Files (
.
)| .” --window-icon=“gtk-folder”
–filename=/usr/share/backgrounds/ --title=“Select Wallpaper Directory”)"

Quit if the BGDIR isn’t set (Cancel is clicked)

[[ -z “$BGDIR” ]] && exit 0

TIME=$(zenity --list --radiolist --column=“Pick”
–column=“Num” --column=“Time interval”
–text=“Pick the time interval\nOk to continue\nCancel to quit” --title=“Select interval”
false 1 " 5 minutes" false 2 “15 minutes” false 3 “30 minutes” true 4
“1 hour” false 5 " 2 hours" false 6 " 3 hours" false 7 “custom”
–width=500 --height=400)
case $TIME in
1) INTERVAL=300 ;;
2) INTERVAL=900 ;;
3) INTERVAL=1800 ;;
4) INTERVAL=3600 ;;
5) INTERVAL=7200 ;;
6) INTERVAL=10800 ;;
7) INTERVAL=$(zenity --scale --text=“Select the interval between\nthe wallpaper change event (in seconds)”
–title=“Select interval in seconds” --value=15 --min-value=5 --window-icon=“gtk-panel-clock”) ;;
*) exit 0 ;;
esac

Quit if the INTERVAL isn’t set

[[ -z “$INTERVAL” ]] && exit 0

while : ; do
find “$BGDIR” -type f -iname *.gif -o -iname *.jpg
-o -iname *.png -o -iname *.jpeg -o -iname *.bmp
-exec gsettings set org.mate.background picture-filename {} ; -exec sleep $INTERVAL ;
done;
[/code]

I replaced Variety too but with this scripts that also time-stamp the wallpaper:

Allowed modes:

  • don’t change the wallpaper (only update the clock)
  • randomly change every minute
  • randomly change every 5 minutes (from the last change)
  • randomly change when the clock minutes ends in 0 or 5 (my favourite)
  • choose one from a list in order every minute

I also added a couple of caja actions to:

  • change the mode
  • change the wallpaper now (next)
  • set a specific wallpaper (from a file inside the wallpaper folder)

Note: all the wallpapers must have the same resolution as the screen (the script doesn’t adjust it)

1 Like