This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How execute javascript inside of plasma-desktop

Tags: None
(comma "," separated)
User avatar
dcell
Registered Member
Posts
11
Karma
0
OS
Hello everyone,

I'm trying to execute the following script that changes the wallpaper in plasma, but are having some difficulties executing it the way I would like.

Code: Select all
var activity = activities()[0];
activity.currentConfigGroup = new Array("Wallpaper", "image");
activity.writeConfig("wallpaper", "/home/dcell/silkwall.png");
activity.reloadConfig();


Now, this script works very well, but the problem I'm having is executing it. The way I've been executing it is by running the following command, which opens up a window with my code in it and an execute button that can run the script.

Code: Select all
qdbus-qt4 org.kde.plasma-desktop /App local.PlasmaApp.loadScriptInInteractiveConsole ~/myscript


I'm using the script inside of another program, so I woud really like it if I could execute this script without having the gui open and then having to select execute. So in other words a qdbus command to execute the script for me, kind of like how the default desktop settings program does it.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I'm afraid that Plasma Desktop doesn't support such automatic execution of scripts, only the manual execution you are currently using. You could automate the selection of "Execute" using xte however.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
dcell
Registered Member
Posts
11
Karma
0
OS
bcooksley wrote:I'm afraid that Plasma Desktop doesn't support such automatic execution of scripts, only the manual execution you are currently using. You could automate the selection of "Execute" using xte however.


That's unfortunate, but if I can't execute it that way, then maybe there's an alternative method I could perform. For example, the way that "default desktop settings" changes it in the same method that the script above does, only it doesn't pop open the window to execute it. I could be mistaken, but I doubt default desktop settings automates the execution of the script, or it has a different method of changing it, which I would be interested in looking at.

I would like to check the source code for default desktop settings, but I have no idea where to look. I don't even know the the actual program's name is, or if it's packaged with plasma. Would you mind pointing me in the right direction of the source code, if there is any?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The Default Desktop settings window is part of the actual Plasma Desktop process itself, which is how it is able to perform these changes. Unfortunately i'm not sure exactly where the code is located for the window itself - as Plasma uses a highly plugin based approach, I suspect the code will be located somewhere in the wallpaper though.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
blindvic
Registered Member
Posts
157
Karma
0
OS
Here is how I change the wallpaper using Python: https://github.com/warvariuc/mykde/blob ... _init__.py

Code: Select all
        activity_manager = dbus.SessionBus().get_object(
            'org.kde.ActivityManager', '/ActivityManager/Activities')
        current_activity_id = dbus.Interface(
            activity_manager, 'org.kde.ActivityManager.Activities').CurrentActivity()

        konf_path = self.make_abs_path('~/.kde/share/config/plasma-desktop-appletsrc')
        # http://api.kde.org/pykde-4.7-api/kdecore/KConfig.html
        konf = kdecore.KConfig(konf_path, kdecore.KConfig.SimpleConfig)
        containments = konf.group('Containments')
        for group_name in containments.groupList():
            group = containments.group(group_name)
            # http://api.kde.org/pykde-4.7-api/kdecore/KConfigGroup.html
            if group.readEntry('activityId') == current_activity_id:
                wallpaper_image_group = group.group('Wallpaper').group('image')
                wallpaper_image_group.writeEntry('wallpaper', wallpaper_path)
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please note that Plasma Desktop won't pick this up until it's restarted, and your changes could potentially be overwritten by Plasma Desktop itself when it exits.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
blindvic
Registered Member
Posts
157
Karma
0
OS
Yes, that the line `affects = [mykde.Plasma]` which ensures that Plasma is stopped before making this stuff and then started again.
User avatar
JaKi
Registered Member
Posts
109
Karma
0
OS
blindvic wrote:Here is how I change the wallpaper using Python: https://github.com/warvariuc/mykde/blob ... _init__.py


Can this be executed as a servicemenu for dolphin? I am looking for a way to browse by photos with dolphin (fullscreen, not widescreen monitor, so no space to drag and drop) and then just rightclick on an image file and choose "set as wallpaper"...
User avatar
blindvic
Registered Member
Posts
157
Karma
0
OS
JaKi wrote:Can this be executed as a servicemenu for dolphin? I am looking for a way to browse by photos with dolphin (fullscreen, not widescreen monitor, so no space to drag and drop) and then just rightclick on an image file and choose "set as wallpaper"...

Yes, but only after you change it to a script that takes path to the wallpaper as a command line argument. I can do that, if you can't.
User avatar
JaKi
Registered Member
Posts
109
Karma
0
OS
blindvic wrote:Yes, but only after you change it to a script that takes path to the wallpaper as a command line argument. I can do that, if you can't.


That would be great!!
User avatar
blindvic
Registered Member
Posts
157
Karma
0
OS


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]