7

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

3 Answers 3

5

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",
                                     "org.kde.image",
                                     "General");
        d.writeConfig("Image", "file:///path/to/imagefile")
    }}
'

I also found a pythonic solution.

3

kwriteconfig5 --file "$HOME/.config/plasma-org.kde.plasma.desktop-appletsrc" --group 'Containments' --group '1' --group 'Wallpaper' --group 'org.kde.image' --group 'General' --key 'Image' "/path/to/file.png"

Reddit.com. 2022. Change wallpaper from terminal. [online] Available at: http://reddit.com/comments/65pmhj/comment/icfca29/?utm_source=share&utm_medium=web2x&context=3 [Accessed 11 August 2022].

0

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
do

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

# pausetime between iterations
sleeptime=900
# location of wallpapers folder
location="/home/myusername/Pictures"

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

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

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

echo 
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",
                                    "org.kde.image",
                                    "General");
        d.writeConfig("Image", "file://'''$location'''/'${wallpaper}'");
}'
sleep $sleeptime

done

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .