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",
});