Linux how to get window title with just shell script?











up vote
0
down vote

favorite












I cannot install any tools like screen or xproc on the box. I dont need to modify the title, I only need to find the window title name.



echo -e "33]0;[title]7"; modifies the title I know. But I just want to know the existing title name.










share|improve this question




















  • 1




    does unix.stackexchange.com/a/122870/117549 do it for you?
    – Jeff Schaller
    Nov 12 at 15:27






  • 1




    or possibly unix.stackexchange.com/a/274386/117549
    – Jeff Schaller
    Nov 12 at 15:28










  • my os does not recognize those as commands
    – Bootham Deyyam
    Nov 12 at 16:39










  • printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
    – qubert
    Nov 12 at 16:46












  • I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
    – Bootham Deyyam
    Nov 13 at 15:38

















up vote
0
down vote

favorite












I cannot install any tools like screen or xproc on the box. I dont need to modify the title, I only need to find the window title name.



echo -e "33]0;[title]7"; modifies the title I know. But I just want to know the existing title name.










share|improve this question




















  • 1




    does unix.stackexchange.com/a/122870/117549 do it for you?
    – Jeff Schaller
    Nov 12 at 15:27






  • 1




    or possibly unix.stackexchange.com/a/274386/117549
    – Jeff Schaller
    Nov 12 at 15:28










  • my os does not recognize those as commands
    – Bootham Deyyam
    Nov 12 at 16:39










  • printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
    – qubert
    Nov 12 at 16:46












  • I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
    – Bootham Deyyam
    Nov 13 at 15:38















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I cannot install any tools like screen or xproc on the box. I dont need to modify the title, I only need to find the window title name.



echo -e "33]0;[title]7"; modifies the title I know. But I just want to know the existing title name.










share|improve this question















I cannot install any tools like screen or xproc on the box. I dont need to modify the title, I only need to find the window title name.



echo -e "33]0;[title]7"; modifies the title I know. But I just want to know the existing title name.







linux terminal-emulator window window-title






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 2:20









mosvy

4,458321




4,458321










asked Nov 12 at 15:25









Bootham Deyyam

6




6








  • 1




    does unix.stackexchange.com/a/122870/117549 do it for you?
    – Jeff Schaller
    Nov 12 at 15:27






  • 1




    or possibly unix.stackexchange.com/a/274386/117549
    – Jeff Schaller
    Nov 12 at 15:28










  • my os does not recognize those as commands
    – Bootham Deyyam
    Nov 12 at 16:39










  • printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
    – qubert
    Nov 12 at 16:46












  • I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
    – Bootham Deyyam
    Nov 13 at 15:38
















  • 1




    does unix.stackexchange.com/a/122870/117549 do it for you?
    – Jeff Schaller
    Nov 12 at 15:27






  • 1




    or possibly unix.stackexchange.com/a/274386/117549
    – Jeff Schaller
    Nov 12 at 15:28










  • my os does not recognize those as commands
    – Bootham Deyyam
    Nov 12 at 16:39










  • printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
    – qubert
    Nov 12 at 16:46












  • I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
    – Bootham Deyyam
    Nov 13 at 15:38










1




1




does unix.stackexchange.com/a/122870/117549 do it for you?
– Jeff Schaller
Nov 12 at 15:27




does unix.stackexchange.com/a/122870/117549 do it for you?
– Jeff Schaller
Nov 12 at 15:27




1




1




or possibly unix.stackexchange.com/a/274386/117549
– Jeff Schaller
Nov 12 at 15:28




or possibly unix.stackexchange.com/a/274386/117549
– Jeff Schaller
Nov 12 at 15:28












my os does not recognize those as commands
– Bootham Deyyam
Nov 12 at 16:39




my os does not recognize those as commands
– Bootham Deyyam
Nov 12 at 16:39












printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
– qubert
Nov 12 at 16:46






printf 'e[21t' should cause your terminal to return its title in the form e]titlee\ . I'll try to wrap that in a script if they don't delete your question until then.
– qubert
Nov 12 at 16:46














I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
– Bootham Deyyam
Nov 13 at 15:38






I tried the above and got the result below, this is definitely in the right direction, as I was not getting any output before. print "33[21t" >$(tty) IFS='' read -t 3 -r a output : ^l^[
– Bootham Deyyam
Nov 13 at 15:38












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try the following, but notice that the compatibility is pretty limited. See the notes below.



get_title(){(
set -e
ss=`stty -g`; trap 'exit 11' INT QUIT TERM; trap 'stty "$ss"' EXIT
e=`printf '33'`; st=`printf '234'`; t=
stty -echo -icanon min 0 time "${2:-2}"
printf "${1:-33[21t}" > `tty`
while c=`dd bs=1 count=1 2>/dev/null` && [ "$c" ]; do
t="$t$c"
case "$t" in
$e*$e\|$e*$st)
t=${t%$e\}; t=${t%$st}; printf '%sn' "${t#$e][lL]}";
exit 0;;
$e*);;
*) break;;
esac
done
printf %s "$t"; exit 1
)}


Example:



$ get_title
$ title=`get_title`


Or, if your script's stdin is not the terminal:



$ title=`get_title </dev/tty`


The stty + dd kludge tries to make sure that the script won't just block if the terminal doesn't report anything in response to the e[21t escape. This (or a better) approach could be also used with other control sequences (eg. to get the cursor position).



Notes:



Since the e[21t escape is considered "insecure", extra configuration is needed in order to make it work:



For xterm: echo '*.vt100.allowWindowOps: true' | xrdb -override



For urxvt: echo 'Rxvt.insecure: true' | xrdb -override



It will not work at all in vte-based terminals like gnome-terminal, mate-terminal, xfce4-terminal, etc, since they report either a fake ("Terminal") or empty title in response.



mlterm doesn't need anything special, but it will crash (!) if the title wasn't set before with e]2;TITLEa.



screen will report its own window title (the one that was set with the -t option or the C-a A command, not the title of the window it's running in.



It's blocked and not supported in tmux.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481285%2flinux-how-to-get-window-title-with-just-shell-script%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Try the following, but notice that the compatibility is pretty limited. See the notes below.



    get_title(){(
    set -e
    ss=`stty -g`; trap 'exit 11' INT QUIT TERM; trap 'stty "$ss"' EXIT
    e=`printf '33'`; st=`printf '234'`; t=
    stty -echo -icanon min 0 time "${2:-2}"
    printf "${1:-33[21t}" > `tty`
    while c=`dd bs=1 count=1 2>/dev/null` && [ "$c" ]; do
    t="$t$c"
    case "$t" in
    $e*$e\|$e*$st)
    t=${t%$e\}; t=${t%$st}; printf '%sn' "${t#$e][lL]}";
    exit 0;;
    $e*);;
    *) break;;
    esac
    done
    printf %s "$t"; exit 1
    )}


    Example:



    $ get_title
    $ title=`get_title`


    Or, if your script's stdin is not the terminal:



    $ title=`get_title </dev/tty`


    The stty + dd kludge tries to make sure that the script won't just block if the terminal doesn't report anything in response to the e[21t escape. This (or a better) approach could be also used with other control sequences (eg. to get the cursor position).



    Notes:



    Since the e[21t escape is considered "insecure", extra configuration is needed in order to make it work:



    For xterm: echo '*.vt100.allowWindowOps: true' | xrdb -override



    For urxvt: echo 'Rxvt.insecure: true' | xrdb -override



    It will not work at all in vte-based terminals like gnome-terminal, mate-terminal, xfce4-terminal, etc, since they report either a fake ("Terminal") or empty title in response.



    mlterm doesn't need anything special, but it will crash (!) if the title wasn't set before with e]2;TITLEa.



    screen will report its own window title (the one that was set with the -t option or the C-a A command, not the title of the window it's running in.



    It's blocked and not supported in tmux.






    share|improve this answer



























      up vote
      0
      down vote













      Try the following, but notice that the compatibility is pretty limited. See the notes below.



      get_title(){(
      set -e
      ss=`stty -g`; trap 'exit 11' INT QUIT TERM; trap 'stty "$ss"' EXIT
      e=`printf '33'`; st=`printf '234'`; t=
      stty -echo -icanon min 0 time "${2:-2}"
      printf "${1:-33[21t}" > `tty`
      while c=`dd bs=1 count=1 2>/dev/null` && [ "$c" ]; do
      t="$t$c"
      case "$t" in
      $e*$e\|$e*$st)
      t=${t%$e\}; t=${t%$st}; printf '%sn' "${t#$e][lL]}";
      exit 0;;
      $e*);;
      *) break;;
      esac
      done
      printf %s "$t"; exit 1
      )}


      Example:



      $ get_title
      $ title=`get_title`


      Or, if your script's stdin is not the terminal:



      $ title=`get_title </dev/tty`


      The stty + dd kludge tries to make sure that the script won't just block if the terminal doesn't report anything in response to the e[21t escape. This (or a better) approach could be also used with other control sequences (eg. to get the cursor position).



      Notes:



      Since the e[21t escape is considered "insecure", extra configuration is needed in order to make it work:



      For xterm: echo '*.vt100.allowWindowOps: true' | xrdb -override



      For urxvt: echo 'Rxvt.insecure: true' | xrdb -override



      It will not work at all in vte-based terminals like gnome-terminal, mate-terminal, xfce4-terminal, etc, since they report either a fake ("Terminal") or empty title in response.



      mlterm doesn't need anything special, but it will crash (!) if the title wasn't set before with e]2;TITLEa.



      screen will report its own window title (the one that was set with the -t option or the C-a A command, not the title of the window it's running in.



      It's blocked and not supported in tmux.






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        Try the following, but notice that the compatibility is pretty limited. See the notes below.



        get_title(){(
        set -e
        ss=`stty -g`; trap 'exit 11' INT QUIT TERM; trap 'stty "$ss"' EXIT
        e=`printf '33'`; st=`printf '234'`; t=
        stty -echo -icanon min 0 time "${2:-2}"
        printf "${1:-33[21t}" > `tty`
        while c=`dd bs=1 count=1 2>/dev/null` && [ "$c" ]; do
        t="$t$c"
        case "$t" in
        $e*$e\|$e*$st)
        t=${t%$e\}; t=${t%$st}; printf '%sn' "${t#$e][lL]}";
        exit 0;;
        $e*);;
        *) break;;
        esac
        done
        printf %s "$t"; exit 1
        )}


        Example:



        $ get_title
        $ title=`get_title`


        Or, if your script's stdin is not the terminal:



        $ title=`get_title </dev/tty`


        The stty + dd kludge tries to make sure that the script won't just block if the terminal doesn't report anything in response to the e[21t escape. This (or a better) approach could be also used with other control sequences (eg. to get the cursor position).



        Notes:



        Since the e[21t escape is considered "insecure", extra configuration is needed in order to make it work:



        For xterm: echo '*.vt100.allowWindowOps: true' | xrdb -override



        For urxvt: echo 'Rxvt.insecure: true' | xrdb -override



        It will not work at all in vte-based terminals like gnome-terminal, mate-terminal, xfce4-terminal, etc, since they report either a fake ("Terminal") or empty title in response.



        mlterm doesn't need anything special, but it will crash (!) if the title wasn't set before with e]2;TITLEa.



        screen will report its own window title (the one that was set with the -t option or the C-a A command, not the title of the window it's running in.



        It's blocked and not supported in tmux.






        share|improve this answer














        Try the following, but notice that the compatibility is pretty limited. See the notes below.



        get_title(){(
        set -e
        ss=`stty -g`; trap 'exit 11' INT QUIT TERM; trap 'stty "$ss"' EXIT
        e=`printf '33'`; st=`printf '234'`; t=
        stty -echo -icanon min 0 time "${2:-2}"
        printf "${1:-33[21t}" > `tty`
        while c=`dd bs=1 count=1 2>/dev/null` && [ "$c" ]; do
        t="$t$c"
        case "$t" in
        $e*$e\|$e*$st)
        t=${t%$e\}; t=${t%$st}; printf '%sn' "${t#$e][lL]}";
        exit 0;;
        $e*);;
        *) break;;
        esac
        done
        printf %s "$t"; exit 1
        )}


        Example:



        $ get_title
        $ title=`get_title`


        Or, if your script's stdin is not the terminal:



        $ title=`get_title </dev/tty`


        The stty + dd kludge tries to make sure that the script won't just block if the terminal doesn't report anything in response to the e[21t escape. This (or a better) approach could be also used with other control sequences (eg. to get the cursor position).



        Notes:



        Since the e[21t escape is considered "insecure", extra configuration is needed in order to make it work:



        For xterm: echo '*.vt100.allowWindowOps: true' | xrdb -override



        For urxvt: echo 'Rxvt.insecure: true' | xrdb -override



        It will not work at all in vte-based terminals like gnome-terminal, mate-terminal, xfce4-terminal, etc, since they report either a fake ("Terminal") or empty title in response.



        mlterm doesn't need anything special, but it will crash (!) if the title wasn't set before with e]2;TITLEa.



        screen will report its own window title (the one that was set with the -t option or the C-a A command, not the title of the window it's running in.



        It's blocked and not supported in tmux.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 21:43

























        answered Nov 19 at 18:18









        mosvy

        4,458321




        4,458321






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481285%2flinux-how-to-get-window-title-with-just-shell-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre