It’s probably because the cron job does not have access to your Dbus session. I thought Plasma already comes with a slideshow function, why not use that?
I believe that wallpaper setting are stored in ~/.config/plasma-org.kde.plasma.desktop-appletsrc.
Double checking, mine shows my different wallpaper settings across both my monitors and for all of my Activities.
Thanks @claydoh and @Justin
Modifying ~/.config/plasma-org.kde.plasma.desktop-appletsrc did the trick!
A systemd service sounds like an overengineered solution for this and I am not savvy enough to come up with that anyway.
But eventually I decided to go with the simpler solution of just using the Slideshow mode. My script will fetch a wallpaper image every night and place it in a directory.
For reference, the systemd solution would look something like this. The systemd timer essentially replaces the cron job: ~/.config/systemd/user/update-desktop.timer:
[Unit]
Description=Periodically update the desktop background
[Timer]
# Trigger when hour and minute are 0 (i.e. midnight)
OnCalendar=0 0 * * *
[Install]
WantedBy=timers.target
~/.config/systemd/user/update-desktop.service:
[Unit]
Description=Update the desktop background with the latest image from somewhere
[Service]
Type=oneshot
# Your script that fetches the image and sets it
ExecStart=/path/to/update-desktop.sh
Once you’ve created these two files, you just need to run systemctl --user enable update-desktop.timer
to enable it.