LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 05-24-2006, 09:12 PM   #1
redleafong
LQ Newbie
 
Registered: May 2006
Posts: 5

Rep: Reputation: 0
Question Get the title of xterm/gnome-terminal


Hi all,

Is there any way to "get" the terminal title? I know how to set it but I can not figure out how to get it. Any one has some ideas? Thanks!
 
Old 05-24-2006, 09:31 PM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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

Last edited by Centinul; 05-24-2006 at 09:35 PM.
 
Old 05-24-2006, 10:49 PM   #3
redleafong
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 05-24-2006, 11:34 PM   #4
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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.
 
Old 05-25-2006, 12:31 AM   #5
redleafong
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 07-13-2009, 10:47 AM   #6
arar
LQ Newbie
 
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
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?
 
Old 01-10-2011, 06:38 PM   #7
sswam
LQ Newbie
 
Registered: Dec 2009
Posts: 10

Rep: Reputation: 1
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change title of xterm - Fedora 2.6 sohnir Linux - General 3 12-13-2005 11:40 AM
xterm title after quittin ssh sessions bujecas Slackware 1 07-01-2005 08:27 PM
custom xterm title when already defined in .bashrc brian0918 Linux - Software 1 06-01-2004 11:17 AM
Need help using xterm or gnome-terminal with -e option?? Rickj42 Programming 1 08-12-2003 12:45 PM
Need help using xterm/gnome-terminal with -e option?? Rickj42 Linux - Software 0 08-11-2003 10:31 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration