You are not logged in.

#1 2021-10-15 07:55:01

dhruv8sh
Member
Registered: 2021-10-15
Posts: 9

Problems changing wallpapers using terminal.

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '
    var allDesktops = desktops();
    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", "/path/to/wallpaper.jpg")
    }'

This script above successfully changes the wallpaper to the desired one. But the problem occurs when I want to change the wallpaper in a directory I do not know. Let's say the wallpaper might be in the same directory as the script and I cannot input the path as "./wallpaper.jpg" or "$(dirname $0)/wallpaper.jpg". This produces no error but does not change the wallpaper either.

Thank you in advance.

Extra info about the system:
        Arch Linux Zen Kernel 5.14.11
        KDE plasma-shell 5.22.5

Offline

#2 2021-10-15 10:35:22

Ammako
Member
Registered: 2021-07-16
Posts: 267

Re: Problems changing wallpapers using terminal.

Is using the full path to the image file not an option?

Offline

#3 2021-10-15 10:40:35

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,244

Re: Problems changing wallpapers using terminal.

"$(dirname $0)" is probably just "." and relative paths won't work - so you probably want to use "$(dirname $(realpath $0))"

Offline

#4 2021-10-15 10:44:41

lmn
Member
Registered: 2021-05-09
Posts: 93
Website

Re: Problems changing wallpapers using terminal.

The scripting language used in Plasma is essentially JavaScript but "$(dirname $0)/wallpaper.jpg" is shell syntax. There is no reason for this to work in the Plasma Desktop Script.
The single quotes prevent the ´$(..)/`part from being interpreted by the shell and are taking literally instead.

The reason why `./wallpaper.jpg` does not work as the context of where the script is located and from where it is executed from are different.
The `./` part refers to the current working directory of whatever process spawns this script. You can treat that as essentially unknown in this case.

You could potentially use the shell portion of your script to find the directory. But you would need to change your quoting for that.

Can you elaborate on what you mean by

I want to change the wallpaper in a directory I do not know

Why is this unknown? Are you writing this for yourself or for other people to use as well?
In the former case why is this unknown? In the latter case are just parts of it unknown ie does the `string userDataPath()` part of  https://develop.kde.org/docs/plasma/scr … -and-paths help alleviate some of the problems you are facing?

PS: also please consider using a proper shebang line for your scripts as this makes is more explicit what calls the script in the end and which capabilities you can expect.

Edit: spelling and terminology

Last edited by lmn (2021-10-15 11:37:49)

Offline

#5 2021-10-16 02:43:39

dhruv8sh
Member
Registered: 2021-10-15
Posts: 9

Re: Problems changing wallpapers using terminal.

Ammako unfortunately, there is no way for me to know the direct path to the file.


Seth, I tried that, but it also did not work!


Imn, I'm sorry I wasn't clearer while stating that... By

I want to change the wallpaper in a directory I do not know

I meant that I wanted to get the direct path to an image file which might be in the same folder/directory as the running script. Also, I know the name of the image file but not the direct path to it. For example:
        The path to file might be something like this,

/home/user/Downloads/NameOfProject/wallpaper.jpg

or

/home/user/Documents/NameOfProject/wallpaper.jpg

But what I know is,

/NameOfProject/wallpaper.jpg

I am writing this script essentially for myself because I distro hop alot and I want the same config everytime. The folder is always unknown because I might download the script and I just want to generalize the whole thing, or it would've been easier to change the wallpaper manually instead.
I can use the shell portion of the script to find the path, but I'm not sure how should I quote it afterwards. Please explain a bit more.
I also did not find any use commands as to find out the exact path of the file in the link you provided.

        Thank you mentioning the Shebang line, I will be more careful in the future.
        I also hope that the question is more clearer.

Offline

#6 2021-10-16 06:16:44

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,244

Re: Problems changing wallpapers using terminal.

You've to wrap the script in double quotes "", the stuff inside single quotes isn't expanded (I assume how this works is that you've a shell script that calls a plasma dbus interface and passes a JS function and you want the function to contain the proper wallpaper path that can and shall be expanded from the shell script which is placed in some wallpaper directory?)

Offline

#7 2021-10-16 10:58:14

lmn
Member
Registered: 2021-05-09
Posts: 93
Website

Re: Problems changing wallpapers using terminal.

You could also move your the wallpaper into a known location like $HOME/.cache/wallpaper.jpg and then use userDataPath() in the js part.

Offline

Board footer

Powered by FluxBB