Auto-"click on" all opened tasks/windows from terminal command?

After spending numerous full days on this stupid issue, I’m desperate. No matter what, I can’t get programs to reliably start without stealing each others’ focus so that the annoying orange highlight (“the program demands attention”) in the task manager appears.

Therefore, I’m now thinking of a different, possible workaround: is there some command that I could run in order to automatically focus (as in “click on”) every item in the task manager, so that they no longer display the “orange nagging” for when I return to the computer and sit down for the day? I hate having to manually click on a bunch of things down there every time I start my machine.

I ideally want something like:

ksimulateclick5 *

Or maybe:

kfocuswindows5 *

Does such a thing exist at all in KDE Plasma?

A possible workaround using a script, as long as you’re using X11, might be to use the wmctrl command. I actually asked ChatGPT to put the following script together using the wmctrl -l command to list all windows and then iterating through all windows listed removing the demands_attention properties, assuming that’s the relevant property which is causing the orange highlight.

Put the following into a script and make it executable:

#!/bin/bash

# Get the list of window IDs with "wmctrl -l" and iterate through each line
while read -r window_id _; do
    # Check if the window ID is valid
    if [[ "$window_id" =~ ^0x[0-9a-fA-F]+$ ]]; then
        # Remove the "demands_attention" property for each window
        wmctrl -i -r "$window_id" -b remove,demands_attention
        echo "Removed demands_attention property for window: $window_id"
    fi
done <<< "$(wmctrl -l)"

echo "Finished removing demands_attention properties for all windows."

If you need it to be delayed, you may want to have it called on startup but have a sleep at the start of the script so that it doesn’t run until apps should’ve opened.

2 Likes

For a possible approach that should work with Wayland (from some quick testing), you could create a KWin script which registers a shortcut, that you can then set a keybinding to and you can simply press the keybinding to clear the demandsAttention property (again, this is assuming that’s the property that’s causing the orange highlight). The code below is adapted from this moveallwindowstoscreen script.

You need to put create a folder somewhere, let’s say it’s just under your home directory (~) called clear-demanding-windows. You want to have the following directory structure with the files noted:

clear-demanding-windows/
├─ contents/
│  ├─ code/
│  │  ├─ main.js
├─ metadata.json

In the main.js file, add the following:

function clearDemandsAttention() {
    // Get a list of all windows.
    var allClients = workspace.clientList();

    // Filter out special windows (desktop, dock, splash, etc.).
    var relevantClients = allClients.filter(function(client) {
        return !client.specialWindow;
    });

    // Go through the remaining windows not filtered out and if the
    // demandsAttention property is true, set it to false.
    for (var i = 0; i < relevantClients.length; ++i) {
        var client = relevantClients[i];
        if (client.demandsAttention) {
            client.demandsAttention = false;
        }
    }
}

// Register a shortcut that we can create set a keybinding for.
if (registerShortcut) {
    registerShortcut("Clear Demanding Windows",
        "Clear Demanding Windows",
        "",
        function() { clearDemandsAttention(); }
    );
}

In the metadata.json file, add the following:

{
    "KPlugin": {
        "Name": "Clear Demanding Windows",
        "Description": "Clear the demandsAttention property from windows.",
        "Icon": "preferences-system-windows-script-test",

        "Authors": [
            {
                "Name": "ExXfceUser"
            }
        ],
        "Id": "clear-demanding-windows",
        "Version": "1.0"
    },
    "X-Plasma-API": "javascript",
    "X-Plasma-MainScript": "code/main.js",
    "KPackageStructure": "KWin/Script"
}

Once you’ve done all that, run the following command to install the script (it will be installed to ~/.local/share/kwin/scripts/):

kpackagetool5 --type=KWin/Script -i ~/clear-demanding-windows/

Then you need to go to System Settings and under Window Management > KWin Scripts, tick on the Clear Demanding Windows script from the list and click Apply. This should give enable the script and you should now have a shortcut that you can set a keybinding to.

Go to Shortcuts > Shortcuts > KWin (KWin may be under a System Settings section) and you should find an empty shortcut for Clear Demanding Windows, which you can set a key binding to.

Hopefully that all works (hoping I’ve copied and pasted the correct things) and while it does mean you need to press a keybinding to do it, it does mean that you actually have a mechanism if you ever want to clear the “demands attention” state of windows in the future without clicking on and focusing them.

2 Likes

Sorry for the delay, but I’m 99% sure now that I’ve got it working using your script. I’m just frustrated by timing it exactly right: I have to estimate how long it takes for all the applications to fully start up, but not make it so delayed that, if I come back to the computer too quickly, I’m still exposed to the orange highlights (because the script has not yet run). I guess I could make it run repeatedly, but then we’re getting into even crazier territory… and I’d have to code that “repeat” mechanism. I guess I could make it run every time that the lockscreen is unlocked, but then I might see it for a split second and be reminded that it’s still a thing…

Either way: thanks for the “AI”-coded script. But since there is no such thing as AI, I assume that it must have just happened to find some human-coded Stack Exchange code example buried somewhere deep down which us humans cannot find easily…

Since I never made a full test of the KDE autostart thing (with all the applications listed there instead of just the Krita test), I don’t know for sure how it behaves if you use that built-in mechanism exclusively. If it does cause the orange highlight (and non-grouped items for VirtualBox), I don’t understand how it wouldn’t bother others. It seems pretty clear that it has to do with programs taking their time to start and then “request focus” once their splashscreen is finished and they are able to bring up the real GUI window.

1 Like

Oh, boy… I only now read this Wayland reply! Yeah… It’s really gonna suck when I’m forced to switch to Wayland, in so many ways… And I bet it will happen juuuuust when I’ve finally got things working with X11…

1 Like

Turns out that there is no noticable delay (at least not in my test just now) when calling the script upon unlocking, so I can do that. Nice.