.

Change KDE wallpaper from the command line


Reading time: about 1 minute

Here’s how you can programmatically change your wallpaper in KDE.

You need to execute the following script inside the Plasma Shell.

desktops().forEach(d => {
  d.currentConfigGroup = Array(
    "Wallpaper",
    "org.kde.image",
    "General");
  d.writeConfig("Image", "file://[FILE_PATH]");
  d.reloadConfig();
});

You can construct this as a string, replace [FILE_PATH] with the path to the image file, and then send a d-bus message to the Plasma Shell. For this, I use the following command.

qdbus6 org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript $scriptText

Python script

Here’s a Python script that downloads a random Anime picture and sets it as wallpaper.

#!/usr/bin/env python
import requests
import subprocess
from pathlib import Path
import tempfile

def set_wallpaper(p: Path):
    p = p.resolve()

    script = """
    desktops().forEach(d => {
        d.currentConfigGroup = Array("Wallpaper",
                                     "org.kde.image",
                                     "General");
        d.writeConfig("Image", "file://FILEPATH");
        d.reloadConfig();
    });
    """.replace("FILEPATH", str(p))

    cmd = [
        "qdbus6",
        "org.kde.plasmashell",
        "/PlasmaShell",
        "org.kde.PlasmaShell.evaluateScript",
        script,
    ]

    subprocess.check_call(cmd, stdout=subprocess.DEVNULL)


def main():
    with tempfile.NamedTemporaryFile() as f:
        p = Path(f.name).resolve()
        url = "https://pic.re/image"
        p.write_bytes(requests.get(url).content)
        set_wallpaper(p)


if __name__ == "__main__":
    main()

Citation

If you find this work useful, please cite it as:
@article{yaltirakli,
  title   = "Change KDE wallpaper from the command line",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2025",
  url     = "https://www.gkbrk.com/change-kde-wallpaper-from-the-command-line"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Change KDE wallpaper from the command line", January, 2025. [Online]. Available: https://www.gkbrk.com/change-kde-wallpaper-from-the-command-line. [Accessed Feb. 22, 2025].
APA Style
Yaltirakli, G. (2025, January 12). Change KDE wallpaper from the command line. https://www.gkbrk.com/change-kde-wallpaper-from-the-command-line
Bluebook Style
Gokberk Yaltirakli, Change KDE wallpaper from the command line, GKBRK.COM (Jan. 12, 2025), https://www.gkbrk.com/change-kde-wallpaper-from-the-command-line

Comments

© 2025 Gokberk Yaltirakli