Ubuntu Mate - Change your desktop wallpaper per commandline

Change Desktop Wallpaper per Commandline

I wanted to change my desktop wallpaper with one click at the toolbar - so I needed a shell script to do this. I came up with this:

#!/bin/bash

DIR="/home/jo/Pictures/wallhaven"
PIC=$(ls $DIR | shuf -n1)
CMPL=$DIR/$PIC
dconf write /org/mate/desktop/background/picture-filename "'$CMPL'"

I use Wallhaven to find some nice wallpapers. Basically the script just ls into your wallpaper directory and pipes the ls output to shuf. It then changes the value for the picture-filename key.

If you want to change your wallpaper after a given time, you could use cron jobs to do this, or just run another script:

#!/bin/bash
while true; do
	/home/jo/Scripts/BackgroundChanger.sh
	sleep 600
done

The script above just executes the script every 5 minutes.

I hope this helped you - if so leave a comment! :)