Solved

How can I capture the Terminal Title?

Posted on 2014-03-07
2
341 Views
Last Modified: 2014-03-18
Hi,

I'm using both RHEL and OS X.  For right now, particularly RHEL, I'd like to extract from the title some text then do something with it (that I can do).  

I've found MANY way to set the title, but none to determine what it currently is!

Thanks!

FYI, the simplest method to set a title for both of these OSs is:
prompt> function winname { printf "\e]2;$1\a"; }
then simply
winname "your cool title"
0
Comment
Question by:Ralph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
serialband earned 500 total points
ID: 39914288
From http://invisible-island.net/xterm/xterm.faq.html

#!/bin/ksh
# Echo the current X term title bar to standard output.
# Written by Icarus Sparry <icarus@bath.ac.uk> 11 Apr 1997
#
exec </dev/tty
old=$(stty -g)
stty raw -echo min 0  time ${1-10}
print "\033[21t\c" > /dev/tty
IFS='' read -r a
stty $old
b=${a#???}
print -R "${b%??}"

$ xprop -id $WINDOWID | grep WM_NAME
WM_NAME(STRING) = "this is my title"
current_title=$(xprop -id $WINDOWID | grep WM_NAME | cut -d= -f2)
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39922779
Minor tweak to the second suggestion - add "-" after the "2" - if the title contains an "=", the above version would stop at that "=".  So, it becomes:

    current_title=$(xprop -id $WINDOWID | grep WM_NAME | cut -d= -f2-)

To be even more thorough (remove the quotes round the message, and the space after the "=", and allow for their being a _NET_WM_NAME value in my Centos output along with the WM_NAME that we want):
current_title=$(xprop -id $WINDOWID | grep '^WM_NAME' | cut -d= -f2-|sed -e 's/^ "//' -e 's/"$//')

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decadeā€¦

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question