0

How can I make the hostname show in the title of an X11 window?

In Linux environments, ssh -Y foohost; ...; bar-gui will open an xwindow for the program with the title "bar-gui (on foohost)". That is, the hostname is automatically appended to the X11 window title when it is running on a remote system. I am running programs on multiple remote systems and I need to tell them apart.

Example: Note the hostname in the title of the window on the right. forwarded gedit from askubuntu

I would like to have the same behavior from a mac client.

(I am not looking to change the terminal title.)

Workaround: xdotool can be used to manually change the title of an x window.

ssh -Y foohost
...
bar-gui &
pid="$!"
# Wait for bar-gui to actually load
win=$(xdotool search --pid "$pid")
xdotool set_window --name "bar-gui (on foohost)" "$win"

This workaround is not ideal so I'm not making it an answer. It needs xdotool installed to work. This would not work great as a bash script or function. There are possibly better ways to use xdotool, but this was the first thing I got working.

Note: Doing ... --name "bar-gui (on foohost)" ... from a linux desktop would cause the title to appear as "bar-gui (on foohost) (on foohost)" because it still appends the hostname automatically.

I am still looking for the mac desktop to automatically include the hostname of remote x11 applications in the window title.

  • What terminal are you using? and what does $TeRM show in the ssh session? f X11 then all works as on othr X11 systems – user151019 Jan 25 at 18:02
  • The remote $TERM was xterm-256color. Xquartz 2.7.10, "Terminal" app. @Mark – plswork04 Jan 25 at 19:12
1

This depends on shell configuration and the exact terminal involved; most things support XTerm Control Sequences though terminals can be configured to deny the use of those escape sequences. What Linux systems often have is shell configuration (usually under /etc/profile.d) that automatically runs the escape sequence to set the title to the hostname. This can also be done manually:

printf "\033]2;this is a test\007"

which should set the title

the worlds most boring terminal example

if not, you'll need to configure the terminal to allow that escape sequence, which will be under the preferences or in a configuration file somewhere, depending.

This can be done automatically from a shell configuration file by generating the appropriate escape sequence with the hostname (or whatever other data you might want):

printf "\033]2;%s\007" $(hostname)
  • As this is on the server why is this not working in th question? – user151019 Jan 26 at 17:07
  • @Mark I do not understand your question. Could you elaborate? – thrig Jan 26 at 17:14
  • Why does the op work on Linux but not on Mac. Your answer explains what is on the server where in your answer is there a difference between the clients. – user151019 Jan 26 at 17:17
  • My examples are from a Mac, which uses the same escape sequences as used on Linux to set terminal titles and such. So your claim "but not on Mac" is false. Could you clarify what you mean by "clients" versus "server" and how you think that distinction matters for terminal escape sequences? The X11 server in my example is running on my Mac. The xterm is also running on my Mac, which means the Mac is both the X11 client and server in this case—but this detail is irrelevant to the escape sequence used to set the terminal title. – thrig Jan 26 at 17:57
  • I want the title of xwindows launched to say what remote they were launched from. I'm not trying to change my terminal title (Though I already do that and it works just fine from the mac Terminal app) – plswork04 Jan 29 at 22:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .