The Complete Computing Environment

Parsing the KDE Lockscreen Configuration and setting x11 root BG


When I am using i3wm it doesn't reliably create KDE Plasma workspaces for each workspace. This script extracts the list of images used in the Screen Locker → Appearance → Slideshow wallpaper type and chooses one at random to set to the root image.

fehbg is a script which selects a random image file and sets it as the X11 root bg

Grab all files in paths selected paths:

kreadconfig5 --file ~/.config/kscreenlockerrc \
             --group Greeter --group Wallpaper --group org.kde.slideshow --group General \
             --key SlidePaths \
    | sed -s 's|,|\n|g' | xargs -I{} find "{}" -type f

You can un-check individual files from the folders, this kreadconfig5 call lists those and normalizes the paths.

kreadconfig5 --file ~/.config/kscreenlockerrc \
             --group Greeter --group Wallpaper --group org.kde.slideshow --group General \
             --key UncheckedSlides \
    | sed -E -s 's|,?file://|\n|g' | sed -E "s|/media/pictures/|/home/rrix/Pictures/|"

These are inserted in to a script – this uses some under-used BASh-isms and noweb syntax to weave it all together:

<(CMD) creates a process substitution – bash will replace that with something like /dev/fd/100,create a sub-process which writes to that file descriptor (also referred to as a named pipe) and then the process being scripted, grep in this case, will read from those "files" which are just the output of multiple other programs. This uses two named pipes and particular grep options

grep -Fx -v <( \
) -f <(
) \
    | grep -v "txt$" | grep -v "tar.gz$" \
    | shuf -n1 | xargs -I{} feh --bg-fill "{}"

fehbg is installed and automated in home-manager and My NixOS configuration

It can be installed in to home-manager with a SystemD timer, too

{pkgs,  ... }:

let fehbg = pkgs.writeShellApplication {
      name = "fehbg";
      runtimeInputs = with pkgs; [ feh gnugrep libsForQt5.kconfig ];
      text = builtins.readFile ../files/;
in {
  home.packages = [ fehbg ]; = {
    Unit.Description = "Change the X11 rootbg.";
    Unit.After = "";

    Service.ExecStart = "${fehbg}/bin/fehbg";
    Service.Type = "oneshot";

  systemd.user.timers.fehbg = {
    Unit.Description = "Change the X11 rootbg every half hour.";
    Install.WantedBy = [""];

    # one minute after login
    Timer.OnActiveSec = 60;
    # every 30 minutes there after
    Timer.OnUnitActiveSec = (30 * 60);
    Timer.OnStartupSec = 30;
    Timer.Unit = "fehbg";