Chwp -- Desktop wallpaper changer

I have developed a cool python utility that uses Nitrogen to change wallpapers from a directory, never using the same picture twice until all the pictures have been shown, and rotating x number of seconds (configurable) before the next wallpaper change. It’s called “chwp” and it works flawlessly with my Mabox setup. I would like to make it available for others. Download here.

2 Likes

Hello @Shwaybo,
That sounds interesting, I’d love to try it out :slight_smile:
Have you posted this script somewhere? On github or elsewhere?
If it’s short, you can put it here in post.
Use 3 backticks (```) on their own line above and below your code.

https://fixyourlinux.com/wp-content/uploads/2021/05/chwp.7z

1 Like

Thanks for sharing,
I set a wallpaper change every 30 seconds and I’m looking at them now;)
It works nice :smiley:

Some thoughts…

  1. I like the idea.
  2. Not so easy to setup currently (user need to edit 2 files and make “backup directory” by hand).
  3. Perhaps - sometime in my free time - I’ll try to write something like this, but as a Bash script - my Python skill is very low :wink:

Some ideas for tool changes/improvements

  1. Config file location should be: $HOME/.config/chwp/chwp.conf and it should be created at first run.
  2. Might be better to not copy images anywhere but to store image filenames in list/temporary file(?) and take random line from it - then delete line and so on. This way will be possible to operate on read-only directories like /usr/share/wallpapers
  3. Configurable wallpaper setter command to make script more universal for example on LXDE:
    something like:
pcmanfm --set-wallpaper="$file"
2 Likes

Here it is :slight_smile:

#!/bin/bash
CONFIG_DIR="$HOME/.config/chwp"
CONFIG_FILE="$CONFIG_DIR/chwp.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"

# Make config directory if not exist
mkdir -p $CONFIG_DIR

# If config file not exist create one with defaults
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=10
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
EOF
fi

# read config variables from file
source <(grep = $CONFIG_FILE)

# decide which setter and command use to set wallpaper
case "$setter" in
    nitrogen) command="nitrogen --set-zoom-fill --save";;
    feh) command="feh --bg-fill" ;;
    *) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;;
esac

while true
do
    # If list does not exist or is empty
    if [[ ! -f $WALLPAPERS_LIST || $(wc -l <$WALLPAPERS_LIST) -lt 1 ]]; then
    # Prepare list with wallpapers (only PNG and JPG)
    ls -1 "$wallpaper_dir"/*{.jpg,.png} > "$WALLPAPERS_LIST"
    fi
    
    # if wallpapers list have more than 0 lines
    while [ $(wc -l <$WALLPAPERS_LIST) -gt 0 ]
    do
        # get random line
        line=$(shuf -n 1 $WALLPAPERS_LIST)
        #delete it from list
        grep -v "$line" "$WALLPAPERS_LIST" > "$CONFIG_DIR/tmpfile"; mv "$CONFIG_DIR/tmpfile" "$WALLPAPERS_LIST"
        #run command to set wallpaper
        ${command} ${line}
        sleep ${interval}
    done
done
1 Like

Thanks for the script.
Well, my question is - why is wplist file with a list of images needed in the configuration?

Hi @Ved-un good point.
I was writing this script late at night quickly.
A list with pictures has to be saved somewhere.
There is no deeper sense in it, it just turned out like that :wink:

If I have some free time, I will probably rewrite the script + add pipemenu to make it a nice toy that runs from the left sidepanel. (start, stop, configure interval and so on)

1 Like

I have such a script - is it worse?

#!/bin/sh

 while true; do
  nitrogen --set-zoom-fill --random --save
  sleep 900
 done

Here it is completely and I use it.

#!/bin/sh

if [ "$1" = -d ];
then
 while true; do
  nitrogen --set-zoom-fill --random --save
  sleep 900
 done
else
  nitrogen --set-zoom-fill --random --save
fi

@Ved-un your script is fine :slight_smile:

But idea and python program from @Shwaybo is about…

1 Like

Got it.
Then I’ll leave this script for experiments )
although my folder with images is large and repetitions with my script are very rare (imperceptible)