views:

204

answers:

2

I want to write a program which prints the current focused window name and if it is a gnome-terminal, then prints out the running program inside the current gnome-terminal tab (for example vim, if a vim session is running).

To get the currently focused window name, I used:

xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"

xprop -id 0x220ad5a | grep "WM_CLASS(STRING)"

If the current window is a gnome-terminal, this will return 'gnome-terminal'.

But how can I find out the program running inside gnome-terminal (more precisely: inside the current gnome-terminal tab)? I thought about using dbus but gnome-terminal does not seem to support it.

A: 

Get the gnome terminal PID, and check which processes have this number as PPID.

I have answered a very similar question few days ago, see this link for details.

Adam Matan
This may be multiple processes if gnome terminal runs multiple tabs.
dseifert
I believe each tab will have its own PID, because it runs a separate shell.
Adam Matan
A: 

Thanks Adam! I am almost there. With xprop I can get the PID of the gnome-terminal (6736). But unfortunately, there is only one process for all gnome-terminal windows and tabs. See this pstree output with two opened gnome-terminal windows:

 -gnome-terminal(6736)-+-bash(6738)---vim(6780) 

  |                    |-bash(7026)---pstree(7045) 

  |                    | `-{gnome-terminal}(6740) 

Is there a way to find out the bash pid of the currently opened gnome-terminal tab?

Funsi
Not via the ps output. You'd need to somehow query the gnome-terminal application for infos, but I don't know how you would do that. Maybe check the source code?P.S.: To ask for more details on an answer, either post a comment to that answer or edit your question. Adding a new answer will make it hard to read as the order of the answers is not necessarily by time.
dseifert
Yes. It's the one running the `ps` command.
Adam Matan
@adam: :)@dseifert: thanks and ill check the gnome-terminal sourecode this week.
Funsi
I had a look at the sourcecode but unfortunately could not find anything useful for my problem. Seems that I should have a try with another console program.
Funsi