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.
Hello @Shwaybo,
That sounds interesting, I’d love to try it out
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.
Thanks for sharing,
I set a wallpaper change every 30 seconds and I’m looking at them now;)
It works nice
Some thoughts…
- I like the idea.
- Not so easy to setup currently (user need to edit 2 files and make “backup directory” by hand).
- 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
Some ideas for tool changes/improvements
- Config file location should be:
$HOME/.config/chwp/chwp.conf
and it should be created at first run. - 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
- Configurable wallpaper setter command to make script more universal for example on LXDE:
something like:
pcmanfm --set-wallpaper="$file"
Here it is
#!/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
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
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)
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
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)