Raise and focus a window from cli (wayland)

Hi,

I’m trying to raise and focus a window using a script.
I tried tools like xdotool and also a kwin script:

for (var client of workspace.stackingOrder) {
    if(client.caption.match("Viewer")) {
        console.log("Activating", client.caption)
        workspace.activeClient = client;
        workspace.raiseWindow(client);
    }
}

The raise works but the cursor is still in the prev selected window.

Any ideas how I can do it like wmctrl -i -a