9

Configuration of KDE desktop applets, like the launcher ("Kickoff") or the clock is held in ~/.config/plasma-org.kde.plasma.desktop-appletsrc (at least for KDE 5). I'd like to configure the applets on a fresh system to my liking using Ansible, but I can't find a robust way to do that.

I know I can use kwriteconfig5 to change the values there, like so

kwriteconfig5 --file ~/.config/plasma-org.kde.plasma.desktop-appletsrc \
--group Containments --group 3 --group Applets --group 9 \
--group Configuration --group Appearance \
--key dateFormat isoDate

which would hide some items from the system tray if the number of containment (3) and the applet (9) would match to the clock applet like so

[Containments][3][Applets][9]
immutability=1
plugin=org.kde.plasma.digitalclock

which isn't guaranteed to happen between installations, from what I've seen.

Is there some available elegant way to set the values for specific applets (plugins, in the config file)? Or is it necessary to write a script that will dig up the numbers for a specific app and then use the klunky kwriteconfig5 command?

3
  • did you manage to find a solution for this?
    – Or B
    Jan 6, 2022 at 13:43
  • Nope, sorry. And I probably won't, since I've switched to XFCE.
    – butla
    Jan 9, 2022 at 16:18
  • Nowadays I maintain my config and sync laptops with this tool/repo I made for myself. If some command has nice config files (don't change when the app does work or randomly) and plays along, I just keep its config as a file, so that I see its changes in Git. If it's "problematic" I'm running Python (the linked script) to set the file.
    – butla
    Jul 16, 2022 at 12:00

4 Answers 4

1

A simplified solution on bash:

config="plasma-org.kde.plasma.desktop-appletsrc"
grp=""
while IFS= read -r line
do
    [[ $line == *Applets* ]] && grp="$line"
    [[ $line == *org.kde.plasma.digitalclock* ]] && break
done < "$HOME/.config/$config"
ContGrp=$(echo "$grp" | awk -F\] '{print $2}' | awk -F\[ '{print $2}')
ApplGrp=$(echo "$grp" | awk -F\] '{print $4}' | awk -F\[ '{print $2}')

kwriteconfig5 --file "$config" \
  --group Containments --group "$ContGrp" --group Applets --group "$ApplGrp" \
  --group Configuration --group General \
  --key dateFormat isoDate
1

I have identified the best way to do this for Plasma 5.6. They have a scripting API, however, it is in javascript run with QJSEngine. This answer shows how to run the script from bash, configure applets, and add panel widgets. There are more examples in the official documentation. Documentation for the API bindings is available here for further research.

Identifying the specific keys you need to change per widget is best done by reading the applet's main.xml file in the applet source.

Run the script from bash:

contents=$(<"script.js")
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "$contents"
var allPanels = panels();
var done = false;
for (var panelIndex = 0; panelIndex < allPanels.length; panelIndex++) {
    if (done){
        break;
    }
    var p = allPanels[panelIndex];

    var widgets = p.widgets();
    for (var widgetIndex = 0; widgetIndex < widgets.length; widgetIndex++) {
        var w = widgets[widgetIndex];

        // Cycle through panels and widgets until we find the panel with the pager on it.
        if (w.type != "org.kde.plasma.pager"){
            continue;
        }

        // Add new widget to the same panel
        var wt = p.addWidget("org.kde.windowtitle");
        // Print the IDs so you could grab them from bash if you wanted
        print(`${p.id}\t${wt.id}`)

        done = true;
    }
}

(Aside: I found that reordering the panel widgets wouldn't work from the scripting API; they only get added to the config in the AppletOrder key after a delay or something. However, capturing the group IDs lets them be modified from bash or a second script later. Script here for reference)

Here's the example from the documentation directly relevant to the original question:

// See previous examples for these functions.
function forEachWidgetInContainmentList(containmentList, callback) { ... }
function forEachWidget(callback) { ... }
function forEachWidgetByType(type, callback) { ... }

function widgetSetProperty(args) {
    if (!(args.widgetType && args.configGroup && args.configKey)) {
        return;
    }

    forEachWidgetByType(args.widgetType, function(widget){
        widget.currentConfigGroup = [args.configGroup];

        //--- Delete when done debugging
        const oldValue = widget.readConfig(args.configKey);
        print("" + widget.type + " (id: " + widget.id + "):");
        print("\t[" + args.configGroup + "] " + args.configKey + ": " + oldValue + " => " + args.configValue);
        //--- End Debug

        widget.writeConfig(args.configKey, args.configValue);
    });
}

widgetSetProperty({
    widgetType: "org.kde.plasma.digitalclock",
    configGroup: "Appearance",
    configKey: "dateFormat",
    configValue: "isoDate",
});
0

Remove all but the bare minimum configuration, and renumber all items as you wish, only having the Containment #1 and essential Applets.

[Containment][1]
lastScreen=0
location=4
plugin=org.kde.panel

...

Save it into ~/.config/plasma-org.kde.plasma.desktop-appletsrc, and do kquitapp5 plasmashell && kstart5 plasmashell to reload.

With your basic settings and numbers intact, other lacking lines will be automatically added by KDE.

0

I re-wrote Олексій Пирогов's answer as a function:

applet_config="$XDG_CONFIG_HOME/plasma-org.kde.plasma.desktop-appletsrc"

configure_applet(){
  applet="$1"
  confgroup="$2"
  key="$3"
  value="$4"

  grp=""
  while IFS= read -r line
  do
    [[ $line == *Applets* ]] && grp="$line"
    [[ $line == *$applet* ]] && break
  done < "$applet_config"
  ContGrp=$(echo "$grp" | awk -F\] '{print $2}' | awk -F\[ '{print $2}')
  ApplGrp=$(echo "$grp" | awk -F\] '{print $4}' | awk -F\[ '{print $2}')

  kwriteconfig5 --file "$(basename "$applet_config")" \
    --group Containments --group "$ContGrp" --group Applets --group "$ApplGrp" \
    --group Configuration --group General \
    --key "$key" "$value"
}

# Example usage
configure_applet org.kde.plasma.digitalclock General dateFormat "isoDate"
configure_applet org.kde.windowtitle General style 3  # style 3 = Title - Application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.