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).

  • I don't understand what you want to do but have you looked into what wmctrl has to offer? wmctrl isn't installed by default but it's in the repos. – DK Bose Jan 19 '18 at 14:09
  • @DKBose What I want to implement as a keyboard shortcut is: a right click in nautilus/dolphin and click open in terminal. This opens the terminal and changes the PWD as that directory. – subtleseeker Jan 19 '18 at 18:02
  • 1
    I guess this might help: https://askubuntu.com/questions/68078/keyboard-shortcut-for-open-a-terminal-here – shiva Feb 04 '18 at 08:25

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,225
  • Thanks for the response! In simple language, how does right click>open in terminal works in nautilus? It has to capture the present location. – subtleseeker Jan 20 '18 at 11:35
  • That menu is presented by nautilus itself, so it obviously knows the location. – egmont Jan 20 '18 at 13:29
  • This is exactly what I want to convert to keyboard shortcut. Each option in the context menu must have bash-like code which I want to convert to script. – subtleseeker Jan 20 '18 at 14:16
  • "bash-like code" what? I'm really lost here. What is it that you're trying to accomplist at the first place? (See XY Problem.) Graphical applications are meant to be used interactively, not driven from external scripts. – egmont Jan 20 '18 at 15:51
  • Thanks though, I get it now. So I believe that it is not really possible to do what I want here. – subtleseeker Jan 20 '18 at 16:46