Plasma Shell Scripting with KF5: AppletOrder not saved

Oliver Freyermuth o.freyermuth at googlemail.com
Wed Oct 7 11:09:00 BST 2020


(in case I ask at the wrong place, please redirect me)

Dear Plasma devs,

I'm trying to add a quicklaunch to an existing (default-layout) panel directly after the pager, unless it exists already, using plasma shell scripting[0]. 

For this, I have developed the code below, which walks through all panels, finds the pager ID, checks if there already is a quicklaunch, and then (if there's no quicklaunch but there is a pager)
adds a new quicklaunch. 
Finally, I "readConfig" the "AppletOrder" from the "General" ConfigGroup of the panel, and rebuild the AppletOrder shuffling the quicklaunch to the correct place,
and finally call "writeConfig". 

All looks fine and exactly as expected in the debug output in a plasma console, but the AppletOrder is not saved (i.e. it reads back fine during script runtime, but changes are lost once the script finishes). 
This is with plasma-desktop 5.18.5, but I can also reproduce with older versions. 

Am I doing something stupid? Is AppletOrder not supposed to be writable? 
Is there another way to adjust the ordering within a panel? 

Since all "index" values are "-1", I did not try to write these. 

Cheers and hope somebody can point out my mistake (feel free to RTFM me to some documentation or example code),
	Oliver

PS: Please keep me in CC, I'm not subscribed to the list. Thanks! 

[0] https://userbase.kde.org/KDE_System_Administration/PlasmaTwoDesktopScripting

--------------------------------------------------------------------------
for (i = 0; i < panelIds.length; ++i) { //search through the panels
    panel = panelById(panelIds[i]);
    if (!panel) continue;

    haveQuickLaunch = false;
    pagerId = -1;
    
    for (tmpIndex = 0; tmpIndex < panel.widgetIds.length; tmpIndex ++) {
        appletWidget = panel.widgetById(panel.widgetIds[tmpIndex]);
        
        if (appletWidget.type == "org.kde.plasma.pager") {
            pagerId = appletWidget.id;
        }
       
        if (appletWidget.type == "org.kde.plasma.quicklaunch") {
            haveQuickLaunch = true;
        }
       
        print (appletWidget.type + " " + appletWidget.index + " " + tmpIndex + " " + panel.widgetIds[tmpIndex]);
    }
    
    if (!haveQuickLaunch && pagerId != -1) {
        var quicklaunch = panel.addWidget("org.kde.plasma.quicklaunch");
        var qlurls = ["file:///usr/share/applications/firefox.desktop",
                    "file:///usr/share/applications/org.kde.dolphin.desktop"
            ];
        quicklaunch.currentConfigGroup = ["General"];
        quicklaunch.writeConfig("launcherUrls", qlurls);
        panel.currentConfigGroup = ["General"];
        var oldAppOrder = panel.readConfig("AppletOrder").split(";");
        var newAppOrder = [];
        for (appWIdx = 0; appWIdx < oldAppOrder.length; appWIdx++) {
            var oldWIdx = oldAppOrder[appWIdx];
            if (oldWIdx == quicklaunch.id) {
                continue;
            }
            newAppOrder.push(oldWIdx);
            if (oldWIdx == pagerId) {
                newAppOrder.push(quicklaunch.id);
            }
        }
        print ("QuickLaunch ID: " + quicklaunch.id + ", Pager ID: " + pagerId + ", shuffling: " + oldAppOrder.join(';') + " => " + newAppOrder.join(';'));
        panel.writeConfig("AppletOrder", newAppOrder.join(';'));
        panel.reloadConfig();
        print (panel.readConfig("AppletOrder"));
    }
}
--------------------------------------------------------------------------
Output:
 QuickLaunch ID: 78, Pager ID: 17, shuffling: 2;17;4;5;59;49;78 => 2;17;78;4;5;59;49
 2;17;78;4;5;59;49


More information about the Plasma-devel mailing list