• Get terminal/window title

    From Janis Papanagnou@janis_papanagnou@hotmail.com to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 03:18:32 2021
    From Newsgroup: alt.os.linux.ubuntu

    With the standard shell terminal that I use on Ubuntu I can set the
    window title. E.g. by using the GUI menu (Terminal-> Set Title...),
    or by setting it with a shell command, e.g. with something like

    echo -ne "\033]0;SOME TITLE HERE\007"

    Is there an equally simple way to _interrogate_ the window title by
    a shell command?

    Janis
    --- Synchronet 3.18a-Linux NewsLink 1.113
  • From Kaz Kylheku@563-365-8930@kylheku.com to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 01:59:01 2021
    From Newsgroup: alt.os.linux.ubuntu

    On 2021-04-20, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
    With the standard shell terminal that I use on Ubuntu I can set the
    window title. E.g. by using the GUI menu (Terminal-> Set Title...),
    or by setting it with a shell command, e.g. with something like

    echo -ne "\033]0;SOME TITLE HERE\007"

    Is there an equally simple way to _interrogate_ the window title by
    a shell command?

    Yes and no. See here: https://unix.stackexchange.com/a/482818/16369

    Yes and no. There is a ESC[21t sequence. It only works on xterm,
    and a couple other terminals. It's considered a security hole, so
    requires configuration to allow it. Some emulators give a canned answer
    which is not actually the dynamic title.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    --- Synchronet 3.18a-Linux NewsLink 1.113
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 05:18:40 2021
    From Newsgroup: alt.os.linux.ubuntu

    In article <s5la58$2ok$1@news-1.m-online.net>,
    Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
    With the standard shell terminal that I use on Ubuntu I can set the
    window title. E.g. by using the GUI menu (Terminal-> Set Title...),
    or by setting it with a shell command, e.g. with something like

    echo -ne "\033]0;SOME TITLE HERE\007"

    Is there an equally simple way to _interrogate_ the window title by
    a shell command?

    xdotool getactivewindow getwindowname

    should do it (at least as long as the calling window is the active window.

    In fact, it is kind of a weakness in xdotool, that there is no obvious way
    to get information about the calling process's window; using
    getactivewindow is a kludge, but it is likely to work in most cases.

    Thinking about this some more, I suppose what you could do is:

    # At the beginning...
    echo -ne "\033]0;SOME TITLE HERE\007"
    myWinId=$(xdotool search --only --sync --name "SOME TITLE HERE")

    # Then later on...
    # set it to whatever you really want it to...
    echo -ne "\033]0;whatever whatever probably dynamic\007"

    # Then later on...
    echo "My window title is: $(xdotool getwindowname $myWinId)"

    --
    I am not a troll.
    Rick C. Hodgin
    I am not a crook.
    Rick M. Nixon
    --- Synchronet 3.18a-Linux NewsLink 1.113
  • From Richard Harnden@richard.nospam@gmail.com to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 11:07:52 2021
    From Newsgroup: alt.os.linux.ubuntu

    On 20/04/2021 02:18, Janis Papanagnou wrote:
    With the standard shell terminal that I use on Ubuntu I can set the
    window title. E.g. by using the GUI menu (Terminal-> Set Title...),
    or by setting it with a shell command, e.g. with something like

    echo -ne "\033]0;SOME TITLE HERE\007"

    Is there an equally simple way to _interrogate_ the window title by
    a shell command?

    Janis


    If you set the title as part of PS1, then you can query that ... ?
    --- Synchronet 3.18a-Linux NewsLink 1.113
  • From Grant Taylor@gtaylor@tnetconsulting.net to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 09:25:48 2021
    From Newsgroup: alt.os.linux.ubuntu

    On 4/20/21 4:07 AM, Richard Harnden wrote:
    If you set the title as part of PS1, then you can query that ... ?

    That's only reliable while sitting at the prompt. (If even then.)

    All of my systems change the title to be the command as part of a
    pre-command function. So reading $PS1 as part of the command, e.g. a
    script, will return something other than the current window title.



    --
    Grant. . . .
    unix || die
    --- Synchronet 3.18a-Linux NewsLink 1.113
  • From Michael F. Stemper@mstemper@gmail.com to comp.unix.shell,alt.os.linux.ubuntu on Tue Apr 20 12:22:50 2021
    From Newsgroup: alt.os.linux.ubuntu

    On 20/04/2021 05.07, Richard Harnden wrote:
    On 20/04/2021 02:18, Janis Papanagnou wrote:
    With the standard shell terminal that I use on Ubuntu I can set the
    window title. E.g. by using the GUI menu (Terminal-> Set Title...),
    or by setting it with a shell command, e.g. with something like

       echo -ne "\033]0;SOME TITLE HERE\007"

    Is there an equally simple way to _interrogate_ the window title by
    a shell command?


    If you set the title as part of PS1, then you can query that ... ?

    As long as you don't use any variables. For instance,

    $ echo $PS1
    \[\e]0;\u@\h: \w\a\]\u@\h$
    $

    I suppose that there is a definition for all of this that your program
    could use for parsing it out, but that's likely to be error-prone.

    --
    Michael F. Stemper
    Galatians 3:28
    --- Synchronet 3.18a-Linux NewsLink 1.113