I’m running an interactive process in konsole (konsole -> bash -> my_program), and I’d like to have a key shortcut (e.g., Ctrl+Shift+Alt+N) in KDE that automatically runs a script, passing the PID of that process as argument to the script. Multiple konsoles may be running my_program, as different processes, so the keystroke should identify the specific process in the currently focused window, and run the script passing that PID as argument.
Note that, in konsole, all “konsoles” in all desktops are under the same PID. So the parent process for bash is the same as the parent process for another bash running in a different konsole .
I’m able to get the currently focused window using xprop , and I’m able to match it to the KDE window with dbus (it’s using in qdbus "org.kde.konsole-<PID>" /konsole/MainWindow_<ID> winId).
To inspect the process currently running, I need information under /Sessions/<ID> or under /Windows/<ID> in dbus, and I’m not able to connect the MainWindow IDs to the Window or the Session ID.
It’s like /konsole/MainWindow_<ID> has information about the actual X11/Qt/etc widget, and I can find the currently focused window that way, and /Windows/ has more abstract information and it’s corrected to sessions and processes (i.e., bash, my_program), but I can’t find the actively focused window that way.
Any ideas?