Desktop automation. Debian KDE.

user1272047user1272047
3 min read

To automate the KDE 5.7 desktop on Debian 12, you can use a combination of Xdotool, KWin scripting, AutoKey, and KDE's own automation features. Here’s a step-by-step guide:


1. Install Required Tools

Run the following command to install the required packages:

sudo apt update && sudo apt install -y xdotool autokey-gtk autokey-qt wmctrl qdbus kwin-x11

2. Automate Keyboard & Mouse Actions

Using Xdotool (Simulate Mouse & Keyboard Input)

Example: Move the mouse and click

xdotool mousemove 500 500 click 1

Example: Type text into an application

xdotool type "Hello, KDE Automation!"

Example: Press a key combination (Ctrl+Alt+T to open a terminal)

xdotool key ctrl+alt+t

3. Automate Window Management

Using KWin Scripting (KDE’s Built-in Scripting)

  • Open System Settings > Window Management > KWin Scripts

  • Click New, name it, and paste the following JavaScript:

var myWindowRule = new KWin.Rule({
    "description": "Always Maximize Konsole",
    "wmclass": "konsole",
    "maximized": true
});
  • Save and Apply.

Using QDBus (Control KDE Components)

Example: Open Konsole

qdbus org.kde.konsole /Konsole newSession

Example: Toggle KWin desktop grid

qdbus org.kde.kglobalaccel /component/kwin invokeShortcut "Expose"

Example: Switch to Desktop 2

qdbus org.kde.KWin /KWin setCurrentDesktop 2

4. Automate GUI Workflows

Using AutoKey (Macro & GUI Automation)

  1. Open AutoKey (autokey-gtk or autokey-qt)

  2. Click New Script and add:

keyboard.send_keys("<ctrl>+t")
time.sleep(1)
keyboard.send_keys("firefox\n")
  1. Save and Assign a Hotkey.

5. Automate File & System Actions

Using KDE Konsole Profiles

Example: Automatically run commands at startup

  1. Open Konsole > Settings > Manage Profiles

  2. Create a profile, edit the command to:

bash -c 'echo "Automated Task"; sleep 5; exit'
  1. Save and set as default.

Using KDE’s Cron (Task Scheduler)

Example: Run a script every hour

crontab -e

Add:

0 * * * * DISPLAY=:0 /usr/bin/xdotool type "Hello, KDE!"

6. Automate GUI with Python

Using PyAutoGUI

Install:

pip install pyautogui

Example: Move and Click a Button

import pyautogui
pyautogui.click(100, 100)  # Click at coordinates
pyautogui.write("Automated KDE!")  # Type text

7. Automate KDE Panel & Widgets

Reload KDE Panel

killall plasmashell && kstart plasmashell &

Add Widgets via CLI

qdbus org.kde.plasmashell /PlasmaShell evaluateScript \
'var panel = panelById(panelIds[0]); panel.addWidget("org.kde.plasma.clock")'

Final Notes

  • Xdotool → Automate mouse/keyboard actions

  • KWin Scripts → Control window behavior

  • QDBus → Automate KDE system settings

  • AutoKey → Automate keyboard macros

  • Cron → Schedule tasks at system level

  • PyAutoGUI → Automate advanced GUI interactions

Let me know if you need a specific KDE automation script! 🚀

0
Subscribe to my newsletter

Read articles from user1272047 directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

user1272047
user1272047