1

In Kubuntu, I want to capture the address of the active window(if any, else Home). I want this to make a custom keyboard shortcut to open terminal(konsole in kubuntu) in that directory.For eg:gnome-terminal --working-directory=/path/to/dir

EDIT: For dolphin, I found that it is by default Shift+F4 which can be configured easily. But I still want to know how to get the address(aka $PWD) from the active window (of any directory manager). If there is no directory manager open for the instance, then set a default parameter as ~ (Home).

1 Answers1

0

For what application(s) in particular do you wish to have this feature? If a given app doesn't support this, probably the easiest is if you patch it to add this feature.

There are several fundamental problems with the approach you're looking for.

First, I don't know if it's possible to locate the process belonging to a certain window. On X Window (maybe Wayland too, I'm not sure) a window might be opened by a remote process (that is, running on another computer), and no local process belonging to that window. In that case it's obviously impossible to locate the process and figure out its working directory. I'm not sure if there's a way to locate at least the local processes, probably not.

On Wayland, having a global shortcut which peeks into other windows' properties is probably impossible due to its security model, although I'm not familiar with the details.

But let's suppose that somehow you manage to locate the process belonging to the currently active window. Perhaps using heuristics like "if the window title is Files then locate the nautilus process".

You can then easily check the working directory of that process (under /proc/<PID>/cwd), but will it be what you're looking for? Most likely not. I'm not familiar with Dolphin, so let's take Nautilus as our example. It is a single process that can open multiple windows, each showing a different directory. As such, it clearly cannot change its working directory to the one displayed, since there are multiple directories it shows you, yet a single working directory the process can have. So the value under /proc wouldn't get you what you're looking for. There is no reasonable way you could peek into the process's behavior to the extent to figure out which directory path belongs to which window, unless the app somehow explicitly supports providing this information to you.

egmont
  • 8,990
  • 1
  • 34
  • 47