I would like to implement the following functionality, which I could bind to a shortcut:
if a given application is open, switch to it,
if it is not open, start it
A tool that this this on X11 is jumpapp, but it does not support Wayland. I found a script that is supposed to do that (ww-run-raise), but it does not work for KDE 6.
So, the main problem is detecting if an application is “open” - unlike with X11, under Wayland one application cannot detect what other applications are running - its a security thing. You can either write a KWin script that will be able to do that because it runs inside KWin (see this KDE scripting tutorial to try to tackle that), or you can list the system processes using ps or something like that and try to figure out if the application that you are interested in has an active process.
It’s basically the same problem - you can’t know a window other than your own unless you get cooperation from KWin. In a KWin script you can run workspace.activateClient(client, true, false, false) to activate the window if you found its client object. If you know an application’s process ID, you can list all the clients from the KWin workspace and check their pid property until you find the correct one.