Using plasma-apply-wallpaperimage in cron job

I have a script to set the desktop wallpaper image that essentially does the following:

plasma-apply-wallpaperimage $filename

The script works fine if I run it manually. However, if I run it as a cron job, it returns the error:

An error occurred while attempting to set the Plasma wallpaper:
Not connected to D-Bus server

How can one change the desktop wallpaper using a cron job?

1 Like

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?

It’s probably because the cron job does not have access to your Dbus session.

Is there any way to get that information and pass it to the script?

I thought Plasma already comes with a slideshow function, why not use that?

Right now that is what I am doing…

Ultimately, though, I would like to do this all using a script that I can transfer from one computer to another without having to do extra steps.

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.

You could try a systemd service and timer that runs under your user session. That would likely be able to change it.

1 Like

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 :slight_smile: 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.

2 Likes

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.

1 Like

put the following at the beginning of your cron script:

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
export DISPLAY=":0"
export LC_TIME=C
export LC_NUMERIC=C