[comp.windows.x] escape sequence to change title?

brtmac@maverick.ksu.ksu.edu (Brett McCoy) (04/27/91)

Is there an escape sequence that you can feed to an xterm to make it set
the title?  In looking through the source I found where there is a case
switch that looks to be something like that, something like Esc-T, but
it is never used that I can tell.

If this isn't possible, is there any other easy way to change the title
of a window, hopefully from a shell script or something close.  I don't
mind if it is a program that has to be run.


--
Brett McCoy			Computing and Telecommunications Activities
brtmac@maverick.ksu.ksu.edu	Kansas State University
Every woman's a 10.  It just depends upon which base you're counting in.

brown@Cheetahllnl.gov (Dave Brown) (05/17/91)

In article <MIKE-W.91Apr29161743@cs17.cs.aukuni.ac.nz>, mike-w@cs.aukuni.ac.nz (Mike Williams) writes:
>> 
>> >>> In article <MIKE-W.91Apr29145720@cs17.cs.aukuni.ac.nz>, I wrote
>> 
>> Me>   The escape sequence is ESC-<n>-";"-<name>-"^G", where <name> is the title
>> Me>   string, and <n> is 2 to change the title, 1 to change the icon name, or 0
>> Me>   to change both.  The following shell script will demonstrate it for you:
>> Me> [...munged script...]
>> 
>> Me>   Note that those are real control characters in there ... ie. "" == ESC,
>> Me>   "" == CTRL-G.
>> 
<<<<<< Good stuff deleted >>>>>>
>> --
>>     /-------------------- mike-w@cs.aukuni.ac.nz ---------------------\
>>     | Mike Williams, Computer Science, Auckland University, Aotearoa. |
>>     \-------------- What's another word for Thesaurus? ---------------/
>> -- 
>> New administrater uofa.

-- 

I take it none of this stuff works for xview/openlook?


-----------------------------------------------------------------------------
  David S. Brown                 |  Computer Incident Advisory Capability    
  brown@ocelot.llnl.gov          |  Lawrence Livermore National Laboratories 
  .__  / .__                     |  P.O. Box 808, 7000 East Av  L-303
  |  \ \ |__)                    |  Livermore CA 94550       ME(415) 423-9878
  |__/ / |__)                    |  ciac@cheetah.llnl.gov     FAX(415) 294-5054
-----------------------------------------------------------------------------

jc@raven.bu.edu (James Cameron) (05/17/91)

>>>>> On 16 May 91 23:49:37 GMT, brown@Cheetahllnl.gov (Dave Brown) said:

||-> In article <MIKE-W.91Apr29161743@cs17.cs.aukuni.ac.nz>, mike-w@cs.aukuni.ac.nz (Mike Williams) writes:

[...deleted how to change the title on an xterm...]

||-> I take it none of this stuff works for xview/openlook?

||->   David S. Brown  

	Yes, it most certainly will work, if you are using an xterm. 
	It could care less what window server it was running on.  *8-)

	However, it *won't* work for cmdtool or such nonsense, which
	are brain dead anyways.

jc

--
					-- James Cameron  (jc@raven.bu.edu)

Signal Processing and Interpretation Lab.  Boston, Mass  (617) 353-2879
------------------------------------------------------------------------------
"But to risk we must, for the greatest hazard in life is to risk nothing.  For
the man or woman who risks nothing, has nothing, does nothing, is nothing."
	(Quote from the eulogy for the late Christa McAuliffe.)

Stuart.Marks@eng.sun.COM (Stuart Marks) (05/18/91)

	Yes, it most certainly will work, if you are using an xterm. 
	It could care less what window server it was running on.  *8-)
	However, it *won't* work for cmdtool or such nonsense, which
	are brain dead anyways.

You can indeed use escape sequences to change the title string for cmdtool
and shelltool.  The escape sequences do differ, though, so you'll have to
put some smarts into your shell customization file to make this work if
you intend to switch between xterm and cmdtool.  Here are the ksh-isms
that I use:

    case $TERM in
    sun*)
	# Escape sequences for shelltool/cmdtool:
	#   \e]l...\e\		sets window title
	#   \e]L...\e\		sets icon label
	titleprefix="$(print -n '\033]l')"
	titlesuffix="$(print -n '\033\')"
	iconprefix="$(print -n '\033]L')"
	iconsuffix="$(print -n '\033\')"
	;;
    xterm*)
	# Escape sequences for xterm:
	#   \e]0;...^G		sets both icon and window
	#   \e]1;...^G		sets icon label
	#   \e]2;...^G		sets window title
	titleprefix="$(print -n '\033]2;')"
	titlesuffix="$(print -n '\007')"
	iconprefix="$(print -n '\033]1;')"
	iconsuffix="$(print -n '\007')"
	;;
    *)
	;;
    esac

    function posttitle { print -n "${titleprefix}${1}${titlesuffix}" ; }
    function posticon  { print -n "${iconprefix}${1}${iconsuffix}" ; }
    function postboth  { posttitle "$1" ; posticon "$1" ; }

Enjoy,

s'marks

Stuart W. Marks			ARPA: smarks@eng.sun.com
Windows & Graphics Software	UUCP: sun!smarks
Sun Microsystems, Inc.

guy@auspex.auspex.com (Guy Harris) (05/20/91)

>	However, it *won't* work for cmdtool or such nonsense, which
>	are brain dead anyways.

Yup, the escape sequences you use to change the window or icon titles in
"shelltool"/"cmdtool" are different from the ones you use in "xterm"
(SunView's "(shell,cmd)tool" and XView's "(shell,cmd)tool" accept the
same escape sequences for that - hell, the *code* is largely the
same...).

They're also different from the one you use in "tm"....

scott@statsci.UUCP (Scott Blachowicz) (05/22/91)

Regarding Re: escape sequence to change title? ; Stuart Marks <uunet!eng.sun.com!Stuart.Marks> writes:
> You can indeed use escape sequences to change the title string for cmdtool
> and shelltool.  The escape sequences do differ, though, so you'll have to
> put some smarts into your shell customization file to make this work if
> you intend to switch between xterm and cmdtool.  Here are the ksh-isms
> that I use:

>     case $TERM in
>     sun*)
> 	# Escape sequences for shelltool/cmdtool:
> 	#   \e]l...\e\		sets window title
> 	#   \e]L...\e\		sets icon label
> 	titleprefix="$(print -n '\033]l')"
> 	titlesuffix="$(print -n '\033\')"
> 	iconprefix="$(print -n '\033]L')"
> 	iconsuffix="$(print -n '\033\')"
> 	;;
>     xterm*)
> 	# Escape sequences for xterm:
> 	#   \e]0;...^G		sets both icon and window
> 	#   \e]1;...^G		sets icon label
> 	#   \e]2;...^G		sets window title
> 	titleprefix="$(print -n '\033]2;')"
> 	titlesuffix="$(print -n '\007')"
> 	iconprefix="$(print -n '\033]1;')"
> 	iconsuffix="$(print -n '\007')"
> 	;;
>  ...
.or in csh and in case you use hpterm...(you can extrapolate the
icons from the above...hpterm's icon_pre would be '^[&f-1k${icon_len}D', and
you add a 'set icon_len ...' to the aliases).

	if ($?DISPLAY) then
		switch ($TERM)
			case xterm*:
				set title_pre = '^[]2;'
				set title_post = '^G'
			breaksw

			case *hpterm*:
				set title_pre = '^[&f0k${title_len}D'
				set title_post = ''
			breaksw

			case sun*:
				set title_pre = '^[]l'
				set title_post = '^[\'
			breaksw
		endsw
	endif

   if ($?title_pre && $?title_post) then
	   alias cd	'chdir  \!* ; set title_len=`expr length "${host}/${LOGNAME} : $cwd"`; set prompt = "${title_pre}${host}/${LOGNAME} : ${cwd}${title_post}$logstr.$host.$cwd:t> "'
	   alias push	'pushd  \!* ; set title_len=`expr length "${host}/${LOGNAME} : $cwd"`; set prompt = "${title_pre}${host}/${LOGNAME} : ${cwd}${title_post}$logstr.$host.$cwd:t> "'
	   alias pop	'popd  \!* ; set title_len=`expr length "${host}/${LOGNAME} : $cwd"`; set prompt = "${title_pre}${host}/${LOGNAME} : ${cwd}${title_post}$logstr.$host.$cwd:t> "'
      set title_len=`expr length "${host}/${LOGNAME} : $cwd"`
      set prompt = "${title_pre}${host}/${LOGNAME} : ${cwd}${title_post}$logstr.$host.$cwd:t> "
   else
	   set prompt = "$logstr.$host.$cwd:t> "
	   alias cd 	'chdir \!* ; set prompt = "$logstr.$host.$cwd:t> "'
   	alias push  'pushd \!* ; set prompt = "$logstr.$host.$cwd:t> "'
   	alias pop  'popd \!* ; set prompt = "$logstr.$host.$cwd:t> "'
   endif

Enjoy!

Scott Blachowicz    USPS:  Statistical Sciences, Inc    Voice: 206/283-8802
                           1700 Westlake Ave N, #500
                           Seattle, WA USA  98109
E-mail:  scott@statsci.com
.or..   uunet!statsci!scott
.or..   scott%statsci.uucp@coco.ms.washington.edu

melby@daffy.yk.Fujitsu.CO.JP (John B. Melby) (05/22/91)

I use the following csh alias (much shorter than the other alternatives I've
seen here) to change the title on my kterms:

    alias xtitle 'sh -c "(echo -n ""^[]2\;"\!*"^G"") >&2"'

-----
John B. Melby
Fujitsu Limited, Machida, Japan
melby%yk.fujitsu.co.jp@fai.com

jmsellens@watdragon.waterloo.edu (John M. Sellens) (05/25/91)

In article <MELBY.91May23013939@daffy.yk.Fujitsu.CO.JP> melby@daffy.yk.Fujitsu.CO.JP (John B. Melby) writes:
|I use the following csh alias (much shorter than the other alternatives I've
|seen here) to change the title on my kterms:
|
|    alias xtitle 'sh -c "(echo -n ""^[]2\;"\!*"^G"") >&2"'

I find it much easier to use
    % xtattr -title 'whatever I want it to be'

Also does things like font changing escapes etc.

Anonymous ftp from watmath.waterloo.edu in pub/x11/xterm.escapes, or
export.lcs.mit.edu in contrib/xterm.escapes.