Set screen-title from shellscript

Beerweasle picture Beerweasle · Nov 6, 2009 · Viewed 64.9k times · Source

Is it possible to set the Screen Title using a shell script?

I thought about something like sending the key commands ctrl+A shift-A Name enter

I searched for about an hour on how to emulate keystrokes in an shell script, but didn't find the answer.

Answer

Shirkrin picture Shirkrin · Nov 6, 2009

You can set the screen / xterm title using the following lines:

#!/bin/bash

mytitle="Some title"
echo -e '\033k'$mytitle'\033\\'

[UPDATE] - by request I'm also including the solution proposed by @Espo below:

Depending on your xterm version or your linux distribution the line above may or may not work and you can try the xterm-defaults:

#!/bin/bash

mytitle="Some title"
echo -e '\033]2;'$mytitle'\007'

For more on the details see: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3 or refer to the answer by @Espo below.