How do I set the KDE desktop wallpaper (jpg file) from command line (e.g., by a script, started by the user)?


Sadly, there doesn't seem to be a simple way.

It appears you need to do something like this (from https://www.kubuntuforums.net/showthread.php/66762-Right-click-wallpaper-changer?p=387392&viewfull=1#post387392):

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'var allDesktops = desktops();print (allDesktops);for (i=0;i<allDesktops.length;i++) {d = allDesktops[i];d.wallpaperPlugin = "org.kde.image";d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");d.writeConfig("Image", "file:///media/sda2/Background/SpaceWall/Escape_Function.jpg")}'

or, another example, formatted more nicely (adapted from https://github.com/bharadwaj-raju/libdesktop/issues/1:

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '
    var allDesktops = desktops();
    print (allDesktops);
    for (i=0;i<allDesktops.length;i++) {{
        d = allDesktops[i];
        d.wallpaperPlugin = "org.kde.image";
        d.currentConfigGroup = Array("Wallpaper",
        d.writeConfig("Image", "file:///path/to/imagefile")

I also found a pythonic solution.

| improve this answer | |

Just run this in a script to solve all your problems:

Using Chris' solution:

This is an elaborate answer, however I solved my problems by building on Chris' solution, and I find it far better then KDE's built-in wallpaper functionality - which only works on a single monitor.

Works on all monitors - Just change the variables sleeptime AND location at the top - Copy/Paste into a .sh file and run it.

while true

# //// CONFIGURABLE VARIABLES ////////////

# pausetime between iterations
# location of wallpapers folder

# ////////////////////////////////////////

array=($(ls $location*)) # populate array with directory contents
( IFS=$'\n'; echo "${array[*]}" ) # list array content for debug

index=$(($RANDOM % $size)) 
wallpaper=${array[$index]} # randomly select

echo " || SELLECTED WALLPAPER = "$wallpaper

dbus-send --session --dest=org.kde.plasmashell --type=method_call /PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:
var Desktops = desktops();                                                                                                                       
for (i=0;i<Desktops.length;i++) {
        d = Desktops[i];
        d.wallpaperPlugin = "org.kde.image";
        d.currentConfigGroup = Array("Wallpaper",
        d.writeConfig("Image", "file://'''$location'''/'${wallpaper}'");
sleep $sleeptime


I run this as a startup script and I never have to worry about it again. The cool thing about it is that the array variable which contains all wallpaper filenames - repopulates on every loop, which means I can change my wallpaper loadout and have that reflected in the scripts operation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.