Set KDE Desktop Background?

Just starting out? Need help? Post your questions and find answers here.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Set KDE Desktop Background?

Post 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
Last edited by davebar on Thu May 09, 2019 2:02 pm, edited 2 times in total.
User avatar
macros
User
User
Posts: 88
Joined: Wed Mar 15, 2006 1:47 pm
Location: Munich

Re: Set KDE Desktop Background?

Post 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).
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Set KDE Desktop Background?

Post by davebar »

Thanks macros, pity there is not a simple 1 line api call like windows, but your solution works perfectly for me.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Set KDE Desktop Background?

Post 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
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Set KDE Desktop Background?

Post 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.
User avatar
macros
User
User
Posts: 88
Joined: Wed Mar 15, 2006 1:47 pm
Location: Munich

Re: Set KDE Desktop Background?

Post by macros »

Interesting workaround, thanks for sharing it.
I hope one day KDE devs integrate a direct dbus call for this.
Post Reply