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.
wmctrl
has to offer?wmctrl
isn't installed by default but it's in the repos. – DK Bose Jan 19 '18 at 14:09open in terminal
. This opens the terminal and changes the PWD as that directory. – subtleseeker Jan 19 '18 at 18:02