Solved

How can I capture the Terminal Title?

Posted on 2014-03-07
2
333 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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