DDE Auto change wallpaper via command line

Background

Already grabbed thousands pictures from wallhaven, I wanna to change the wallpaper from them in each five mintues.

It’s easy to change wallpaper via command line, the key point is to figure out how to change lock screen background.

Backup your file

Create a folder named backup at /var/cache/image-blur, move all files in it to that folder.

sudo mkdir -p /var/cache/image-blur/backup
sudo mv /var/cache/image-blur/* /var/cache/image-blur/backup
sudo rm -f /usr/share/wallpapers/deepin/desktop.jpg
sudo rm -f /usr/share/backgrounds/deepin/desktop.jpg

Scripts

set.py

Randomly select one picture, apply wallpaper.

import os
import random

path = '/home/limstash/Pictures/Wallpaper/wallhaven' //images path
filename = random.sample(os.listdir(path), 1)

image = path + "/" + filename[0]
os.system('gsettings set com.deepin.wrap.gnome.desktop.background picture-uri '+image+'')

print(image)

run.sh

Use cron to run it (need root access)

#!/bin/bash

declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"

rm -f /var/cache/image-blur/*

image=`sudo -u limstash -E python3 /home/limstash/Pictures/Wallpaper/scripts/set.py`

cp -f $image /usr/share/wallpapers/deepin/desktop.jpg
cp -f $image /usr/share/backgrounds/deepin/desktop.jpg

IMPORTANT: Don’t forget to change DBUS_SESSION_BUS_ADDRESS
You can use declare -x to see your own envrionment variables

sudo user also need to change

Cron Schedule

Make sure that package cron has already been installed.

sudo crontab -e
*/5 * * * * /home/limstash/Pictures/Wallpaper/scripts/run.sh