# Chwp -- Desktop wallpaper changer

**URL:** https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496
**Category:** Our projects
**Created:** [May 12, 2021, 8:45am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496 "2021-05-12T08:45:57Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Shwaybo](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/shwaybo/32/441_2.png) [@Shwaybo](https://forum.maboxlinux.org/u/Shwaybo)
#### Post date: [May 12, 2021, 8:45am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/1 "2021-05-12T08:45:58Z")

</div>

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.](https://fixyourlinux.com/wp-content/uploads/2021/05/chwp.7z)

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [May 12, 2021, 9:06am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/2 "2021-05-12T09:06:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Shwaybo](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/shwaybo/32/441_2.png) [@Shwaybo](https://forum.maboxlinux.org/u/Shwaybo)
#### Post date: [May 12, 2021, 9:07am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/3 "2021-05-12T09:07:23Z")

</div>

[https://fixyourlinux.com/wp-content/uploads/2021/05/chwp.7z](https://fixyourlinux.com/wp-content/uploads/2021/05/chwp.7z)

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [May 12, 2021, 10:17am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/4 "2021-05-12T10:17:57Z")

</div>

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

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 😉

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:

```auto
pcmanfm --set-wallpaper="$file"

```

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [May 14, 2021, 12:54am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/5 "2021-05-14T00:54:32Z")

</div>

Here it is 🙂

```auto
#!/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

```

---

<div class="post-metadata">

### Author: ![Ved-un](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/ved-un/32/588_2.png) [@Ved-un](https://forum.maboxlinux.org/u/Ved-un)
#### Post date: [May 20, 2021, 9:24am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/6 "2021-05-20T09:24:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [May 20, 2021, 9:35am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/7 "2021-05-20T09:35:28Z")

</div>

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)_

---

<div class="post-metadata">

### Author: ![Ved-un](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/ved-un/32/588_2.png) [@Ved-un](https://forum.maboxlinux.org/u/Ved-un)
#### Post date: [May 20, 2021, 9:59am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/8 "2021-05-20T09:59:37Z")

</div>

I have such a script - is it worse?

```
#!/bin/sh

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

---

<div class="post-metadata">

### Author: ![Ved-un](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/ved-un/32/588_2.png) [@Ved-un](https://forum.maboxlinux.org/u/Ved-un)
#### Post date: [May 20, 2021, 10:01am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/9 "2021-05-20T10:01:50Z")

</div>

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
```

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [May 20, 2021, 10:15am UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/10 "2021-05-20T10:15:38Z")

</div>

@Ved-un your script is fine 🙂

But idea and python program from @Shwaybo is about…

> [@Shwaybo](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Ved-un](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/ved-un/32/588_2.png) [@Ved-un](https://forum.maboxlinux.org/u/Ved-un)
#### Post date: [May 20, 2021, 7:21pm UTC](https://forum.maboxlinux.org/t/chwp-desktop-wallpaper-changer/496/11 "2021-05-20T19:21:15Z")

</div>

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)
