📚 Encyclopedia

Linux Desktop · updated 2026-10-13

Automating KDE Plasma 5 from a shell (qdbus, global shortcuts, taskbar pins, idle inhibit)

kdeplasmaqdbusdbuskglobalaccelgtk4screensaverx11

KDE Plasma 5.27 exposes almost everything over the session D-Bus, so a non-GUI shell (for example a Claude session) can pin apps, register global shortcuts, and inhibit the screen locker without touching the GUI. This article collects the recipes that were proven on VictusPop (Plasma 5.27.12, X11).

Reaching the session from a plain shell

Pin an app to the taskbar

Plasma scripting via qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '<js>': iterate panels(), find widgets of type org.kde.plasma.icontasks, append applications:<name>.desktop to the launchers config in group General, then reloadConfig(). Takes effect live.

Register a global shortcut for a .desktop launcher

  1. Put X-KDE-Shortcuts=Ctrl+Alt+Q in ~/.local/share/applications/<app>.desktop; run kbuildsycoca5.
  2. systemctl --user stop plasma-kglobalaccel.service (stop it first or the daemon overwrites your edit).
  3. kwriteconfig5 --file kglobalshortcutsrc --group <app>.desktop --key _launch "Ctrl+Alt+Q,none,<Friendly Name>" (plus _k_friendly_name).
  4. systemctl --user start plasma-kglobalaccel.service.

KDE grabs the combo before the app sees it, so to make the same combo also exit the app, make the second launch quit the running instance (GtkApplication: do_activate calls self.quit() when already active). Ctrl+Alt+Del is taken by KDE's "Log Out".

Inhibit the idle screen locker

Call org.freedesktop.ScreenSaver.Inhibit on /ScreenSaver and release in shutdown. The hold shows in PowerDevil's PolicyAgent.ListInhibitions only after about 5 s (PowerDevil's registration delay; checking earlier looks like a failure). Lock timing lives in ~/.config/kscreenlockerrc ([Daemon] Timeout=, LockGrace=). If you hold off the lock for hours, consider calling ScreenSaver.Lock on exit so the machine is not left unlocked.

Example: the screen-off tool (~/.local/bin/screen-off, Python + GTK4) shows an undecorated fullscreen black window per monitor, hides the cursor, swallows input, toggles on Ctrl+Alt+Q, and inhibits the locker. It exists because powering the monitor off crashes the session (Powering off an HDMI monitor kills the KDE X11 session (hybrid-GPU laptop)).

Override a system .desktop file per user

Copy it to ~/.local/share/applications/ with the same name, edit, kbuildsycoca5. Undo by deleting the copy. Note the override shadows future package updates of that file.

Example: KDE Discover (and the Updates tray icon) opened no window because plasma-discover deadlocked at startup loading its snap backend. A gdb backtrace showed a lock-order inversion: the main thread held the dynamic-loader lock in dlopen(snap-backend.so) (libsoup-3 initializer) and waited for the GModule lock, while a packagekit-backend thread held the GModule lock and waited for the loader lock in dlopen(libgvfsdbus.so). Fix without root: override org.kde.discover.desktop adding --backends packagekit-backend,fwupd-backend,kns-backend to both Exec= lines (main entry and the Updates action the tray uses). Side effect: snap updates are not listed (snapd refreshes itself anyway). Alternative: sudo apt remove plasma-discover-backend-snap.

Testing tools when xdotool is missing

Gotchas

See also

Linked from

Sources: home memory reference_victuspop_desktop_boot, reference_screen_off_tool, reference_discover_snap_deadlock