Solved

How can I capture the Terminal Title?

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open Camera IP 8 136
address book on outlook 2016 mac 7 72
OS Sierra Time Machine 6 118
Centos 6 User Can't Assign Password 2 41
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…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 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

12 Experts available now in Live!

Get 1:1 Help Now