How to get focused window title in a python or bash script on wayland

Hi, I am trying to find a way to obtain the focused window’s title in plasma 6 (wayland). I want to try and program a basic screen time tracker, getting window titles is the first step. I would like to either do this with a bash script or a python script, however if some languages are easier for this I would use those aswell.

This is not an easy information to obtain in Wayland.
You would need to implement client support for some custom wayland protocol (src/protocols/plasma-window-management.xml · master · Libraries / Plasma Wayland Protocols · GitLab src/protocols/idle.xml · master · Libraries / Plasma Wayland Protocols · GitLab), which are not implemented in any library (you could follow some examples in taskmanager implementation or kwayland).
Only the task manager has access to this normally.

In X11, there is no restriction, you should be able to find existing ways.

1 Like

Ok thanks for the help, looks like this might be beyond my skill level of kde application dev for the moment. So might try and do it in xorg.