Page 1 of 1

Set KDE Desktop Background?

Posted: Sun May 05, 2019 12:15 pm
by davebar
Not sure if I should be posting in Linux section, but this section of the forum seems to be more active.

Can anyone offer any pointers about setting the background (wallpaper) image on a KDE desktop using PB?

TIA
Dave

Re: Set KDE Desktop Background?

Posted: Sun May 05, 2019 12:36 pm
by macros
The only way to do this is by dbus and with scripting:

Code: Select all

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:///PATH/TO/IMAGE.png");
}'
And it doesn't work if widgets are locked and does not throw an error in this case.
But it its the official way. You can utilize it with PBs RunProgram() command.

Otherwise you can search files under ~/.config with plasma in their name, the setting should be stored there somewhere.
But if you use this, the wallpaper won't change till KDE is forced to parse the config files again. Also there is no guarantee that the setting will have the same name in future versions (but it is likely).

Re: Set KDE Desktop Background?

Posted: Mon May 06, 2019 2:07 pm
by davebar
Thanks macros, pity there is not a simple 1 line api call like windows, but your solution works perfectly for me.

Re: Set KDE Desktop Background?

Posted: Thu May 09, 2019 2:11 pm
by davebar
Seems I spoke a little to soon. What I should have said is that it works perfectly, but ONLY ONCE.
If I change the image file name in the script and run it again the wallpaper doesn't change.

What I need is to find is a way to force KDE to parse the config files again. Any thoughts?

TIA

Re: Set KDE Desktop Background?

Posted: Fri May 10, 2019 2:43 pm
by davebar
I found my own workaround (nasty kludge), which was to create a second almost identical script.
My code then uses RunProgram("bash", "./script1.sh", Directory$, #PB_Program_Wait) to run script1 which points to a blank jpg image and then uses RunProgram("bash", "./script2.sh", Directory$, #PB_Program_Wait) to run script2 which points to the valid png image.

Why this works I have no idea and probably nauseates coding purists, the only important thing for me is that it does do what I need.

Re: Set KDE Desktop Background?

Posted: Fri May 10, 2019 2:54 pm
by macros
Interesting workaround, thanks for sharing it.
I hope one day KDE devs integrate a direct dbus call for this.