LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Get the title of xterm/gnome-terminal (http://www.linuxquestions.org/questions/linux-software-2/get-the-title-of-xterm-gnome-terminal-448262/)

redleafong 05-24-2006 09:12 PM

Get the title of xterm/gnome-terminal
 
Hi all,

Is there any way to "get" the terminal title?:confused: I know how to set it but I can not figure out how to get it. Any one has some ideas? Thanks!

Centinul 05-24-2006 09:31 PM

Try running the command:

Code:

xprop WM_CLASS|cut -d \" -f 2|xmessage -file - -center
* name - the name of the window (the first field of WM_CLASS)
* class - class of the window (the second field of WM_CLASS)
* title - title of the window ( WM_NAME property)
* role - role of the window (the WM_WINDOW_ROLE property)
and click on the window in which you want the information. Hope this helps!

Source: Fluxbox Wiki

redleafong 05-24-2006 10:49 PM

Quote:

Originally Posted by Centinul
Try running the command:

Code:

xprop WM_CLASS|cut -d \" -f 2|xmessage -file - -center
* name - the name of the window (the first field of WM_CLASS)
* class - class of the window (the second field of WM_CLASS)
* title - title of the window ( WM_NAME property)
* role - role of the window (the WM_WINDOW_ROLE property)
and click on the window in which you want the information. Hope this helps!

Source: Fluxbox Wiki

Thank you. However this method seems to have to base on interaction with GUI APIs. What I need to do is retrieving the terminal titile in a shell script, so I would like to know if terminal itself supports a way to get its title, just like we can set the terminal title in this way:

echo "\033]2;${title}\007\c"

Thanks.

Centinul 05-24-2006 11:34 PM

From the BASH Guide For Beginners at TLDP they have this:

Code:

$0        Expands to the name of the shell or shell script.
Not sure if it helps or not. Sorry, just trying to help, not very good with this stuff.

redleafong 05-25-2006 12:31 AM

Quote:

Originally Posted by Centinul
From the BASH Guide For Beginners at TLDP they have this:

Code:

$0        Expands to the name of the shell or shell script.
Not sure if it helps or not. Sorry, just trying to help, not very good with this stuff.

Never mind. Thanks.:D

arar 07-13-2009 10:47 AM

So how did you solve it?
 
I'd like to do the same thing and want to know if you found a solution. If so, could you post it here?

sswam 01-10-2011 06:38 PM

it can be done: xtermcontrol... etc
 
I found a C program which can do it with the Xterm control codes and without X11, it works for me:

xtermcontrol --get-title | read A ; echo "$A"

http://www.thrysoee.dk/xtermcontrol/

It should be easy enough to extract / replicate the get_title() function into your own code, or to do it in a different language.

There was a security issue with reading the title, if people cat files such a file could set the title to 'rm -rf /' then 'get' it again which would send that command to your terminal. So sometimes it's disabled by default. The allowWindowOps resource can be used to enable it again.

http://invisible-island.net/xterm/xt...tml#window_ops

I think this security issue has been resolved by escaping the title somehow so it cannot be interpreted as a command. The demo exploit attached here does not work on my system, anyway:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=384593

Getting the title is also described here, but the demo perl code did not work for me:

http://www.perlmonks.org/?node_id=792957

Vim (the version I'm using) relies on X11 to restore the title. If DISPLAY is unset and 'title' is set, vim sets the title to 'Thanks for flying vim!' on exit.

Since I only set terminal titles actively myself, using my own script, the best solution for me might be to store the title in an environment variable $TERM_TITLE, when setting it. Then I can save the old title as needed and restore it later. This workaround would not be much use if you are writing an app which is supposed to work in any environment.


All times are GMT -5. The time now is 04:32 AM.