Solved

How can I capture the Terminal Title?

Posted on 2014-03-07
2
314 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
2 Comments
 
LVL 27

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now