Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I capture the Terminal Title?

Posted on 2014-03-07
2
Medium Priority
?
368 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 30

Accepted Solution

by:
serialband earned 1500 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 20

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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ā€¦

604 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