Extended-to-duplicate monitor script without function key











up vote
0
down vote

favorite












I would like to create a bash script that allows me to:



change the mode of my screen from extended to duplicate and vice versa.



My keyboard does not have the function key and I would like to create a script that will cut me off this operation, but I do not know how to do it



Thanks a lot!










share|improve this question






















  • See stackoverflow.com/help/how-to-ask
    – oguzismail
    Nov 20 at 8:11










  • Can you share the output of this command xrandr --current
    – ArchNoob
    Nov 20 at 8:16















up vote
0
down vote

favorite












I would like to create a bash script that allows me to:



change the mode of my screen from extended to duplicate and vice versa.



My keyboard does not have the function key and I would like to create a script that will cut me off this operation, but I do not know how to do it



Thanks a lot!










share|improve this question






















  • See stackoverflow.com/help/how-to-ask
    – oguzismail
    Nov 20 at 8:11










  • Can you share the output of this command xrandr --current
    – ArchNoob
    Nov 20 at 8:16













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I would like to create a bash script that allows me to:



change the mode of my screen from extended to duplicate and vice versa.



My keyboard does not have the function key and I would like to create a script that will cut me off this operation, but I do not know how to do it



Thanks a lot!










share|improve this question













I would like to create a bash script that allows me to:



change the mode of my screen from extended to duplicate and vice versa.



My keyboard does not have the function key and I would like to create a script that will cut me off this operation, but I do not know how to do it



Thanks a lot!







linux bash ubuntu






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 7:56









Gionata Donati

165




165












  • See stackoverflow.com/help/how-to-ask
    – oguzismail
    Nov 20 at 8:11










  • Can you share the output of this command xrandr --current
    – ArchNoob
    Nov 20 at 8:16


















  • See stackoverflow.com/help/how-to-ask
    – oguzismail
    Nov 20 at 8:11










  • Can you share the output of this command xrandr --current
    – ArchNoob
    Nov 20 at 8:16
















See stackoverflow.com/help/how-to-ask
– oguzismail
Nov 20 at 8:11




See stackoverflow.com/help/how-to-ask
– oguzismail
Nov 20 at 8:11












Can you share the output of this command xrandr --current
– ArchNoob
Nov 20 at 8:16




Can you share the output of this command xrandr --current
– ArchNoob
Nov 20 at 8:16












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










To formulate your bash function, you first need to know the connected screens with this command.



xrandr --current


It will show you an output similar to this



Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
eDP1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 380mm x 210mm
1600x900 60.04*+ 59.82 39.99
1400x900 59.96 59.88
1368x768 60.00 59.88 59.85
1280x800 59.81 59.91
1280x720 59.86 60.00 59.74
1024x768 60.00
1024x576 60.00 59.90 59.82
960x540 60.00 59.63 59.82
800x600 60.32 56.25
864x486 60.00 59.92 59.57
800x450 60.00
640x480 59.94
720x405 59.51 60.00 58.99
640x360 59.84 59.32 60.00
HDMI1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)


As you can see, I have 2 outputs eDPI1 (My laptop screen) and HDMI1 my external monitor that is currently disconnected.



With these variables, I can now write a function that toggles from mirror to extend and back.



#!/bin/bash

export SCREEN_STATE="extended"

function screenToggle() {
if [[ $SCREEN_STATE == "extended" ]]; then
xrandr --output eDPI1 --output HDMI1 --same-as eDPI1
export SCREEN_STATE="mirrored"

else
xrandr --output eDPI1 --output HDMI1 --left-of eDPI1
export SCREEN_STATE="extended"

fi
}


Note that I haven't tested this code and on the first run, the displays will go to mirror mode due to the second line and you can't change that behaviour.



For more values that you may need to pass to control the resolution see man xrandr and this similar question.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f53388510%2fextended-to-duplicate-monitor-script-without-function-key%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
    1
    down vote



    accepted










    To formulate your bash function, you first need to know the connected screens with this command.



    xrandr --current


    It will show you an output similar to this



    Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
    eDP1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 380mm x 210mm
    1600x900 60.04*+ 59.82 39.99
    1400x900 59.96 59.88
    1368x768 60.00 59.88 59.85
    1280x800 59.81 59.91
    1280x720 59.86 60.00 59.74
    1024x768 60.00
    1024x576 60.00 59.90 59.82
    960x540 60.00 59.63 59.82
    800x600 60.32 56.25
    864x486 60.00 59.92 59.57
    800x450 60.00
    640x480 59.94
    720x405 59.51 60.00 58.99
    640x360 59.84 59.32 60.00
    HDMI1 disconnected (normal left inverted right x axis y axis)
    VIRTUAL1 disconnected (normal left inverted right x axis y axis)


    As you can see, I have 2 outputs eDPI1 (My laptop screen) and HDMI1 my external monitor that is currently disconnected.



    With these variables, I can now write a function that toggles from mirror to extend and back.



    #!/bin/bash

    export SCREEN_STATE="extended"

    function screenToggle() {
    if [[ $SCREEN_STATE == "extended" ]]; then
    xrandr --output eDPI1 --output HDMI1 --same-as eDPI1
    export SCREEN_STATE="mirrored"

    else
    xrandr --output eDPI1 --output HDMI1 --left-of eDPI1
    export SCREEN_STATE="extended"

    fi
    }


    Note that I haven't tested this code and on the first run, the displays will go to mirror mode due to the second line and you can't change that behaviour.



    For more values that you may need to pass to control the resolution see man xrandr and this similar question.






    share|improve this answer



























      up vote
      1
      down vote



      accepted










      To formulate your bash function, you first need to know the connected screens with this command.



      xrandr --current


      It will show you an output similar to this



      Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
      eDP1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 380mm x 210mm
      1600x900 60.04*+ 59.82 39.99
      1400x900 59.96 59.88
      1368x768 60.00 59.88 59.85
      1280x800 59.81 59.91
      1280x720 59.86 60.00 59.74
      1024x768 60.00
      1024x576 60.00 59.90 59.82
      960x540 60.00 59.63 59.82
      800x600 60.32 56.25
      864x486 60.00 59.92 59.57
      800x450 60.00
      640x480 59.94
      720x405 59.51 60.00 58.99
      640x360 59.84 59.32 60.00
      HDMI1 disconnected (normal left inverted right x axis y axis)
      VIRTUAL1 disconnected (normal left inverted right x axis y axis)


      As you can see, I have 2 outputs eDPI1 (My laptop screen) and HDMI1 my external monitor that is currently disconnected.



      With these variables, I can now write a function that toggles from mirror to extend and back.



      #!/bin/bash

      export SCREEN_STATE="extended"

      function screenToggle() {
      if [[ $SCREEN_STATE == "extended" ]]; then
      xrandr --output eDPI1 --output HDMI1 --same-as eDPI1
      export SCREEN_STATE="mirrored"

      else
      xrandr --output eDPI1 --output HDMI1 --left-of eDPI1
      export SCREEN_STATE="extended"

      fi
      }


      Note that I haven't tested this code and on the first run, the displays will go to mirror mode due to the second line and you can't change that behaviour.



      For more values that you may need to pass to control the resolution see man xrandr and this similar question.






      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        To formulate your bash function, you first need to know the connected screens with this command.



        xrandr --current


        It will show you an output similar to this



        Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
        eDP1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 380mm x 210mm
        1600x900 60.04*+ 59.82 39.99
        1400x900 59.96 59.88
        1368x768 60.00 59.88 59.85
        1280x800 59.81 59.91
        1280x720 59.86 60.00 59.74
        1024x768 60.00
        1024x576 60.00 59.90 59.82
        960x540 60.00 59.63 59.82
        800x600 60.32 56.25
        864x486 60.00 59.92 59.57
        800x450 60.00
        640x480 59.94
        720x405 59.51 60.00 58.99
        640x360 59.84 59.32 60.00
        HDMI1 disconnected (normal left inverted right x axis y axis)
        VIRTUAL1 disconnected (normal left inverted right x axis y axis)


        As you can see, I have 2 outputs eDPI1 (My laptop screen) and HDMI1 my external monitor that is currently disconnected.



        With these variables, I can now write a function that toggles from mirror to extend and back.



        #!/bin/bash

        export SCREEN_STATE="extended"

        function screenToggle() {
        if [[ $SCREEN_STATE == "extended" ]]; then
        xrandr --output eDPI1 --output HDMI1 --same-as eDPI1
        export SCREEN_STATE="mirrored"

        else
        xrandr --output eDPI1 --output HDMI1 --left-of eDPI1
        export SCREEN_STATE="extended"

        fi
        }


        Note that I haven't tested this code and on the first run, the displays will go to mirror mode due to the second line and you can't change that behaviour.



        For more values that you may need to pass to control the resolution see man xrandr and this similar question.






        share|improve this answer














        To formulate your bash function, you first need to know the connected screens with this command.



        xrandr --current


        It will show you an output similar to this



        Screen 0: minimum 8 x 8, current 1600 x 900, maximum 32767 x 32767
        eDP1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 380mm x 210mm
        1600x900 60.04*+ 59.82 39.99
        1400x900 59.96 59.88
        1368x768 60.00 59.88 59.85
        1280x800 59.81 59.91
        1280x720 59.86 60.00 59.74
        1024x768 60.00
        1024x576 60.00 59.90 59.82
        960x540 60.00 59.63 59.82
        800x600 60.32 56.25
        864x486 60.00 59.92 59.57
        800x450 60.00
        640x480 59.94
        720x405 59.51 60.00 58.99
        640x360 59.84 59.32 60.00
        HDMI1 disconnected (normal left inverted right x axis y axis)
        VIRTUAL1 disconnected (normal left inverted right x axis y axis)


        As you can see, I have 2 outputs eDPI1 (My laptop screen) and HDMI1 my external monitor that is currently disconnected.



        With these variables, I can now write a function that toggles from mirror to extend and back.



        #!/bin/bash

        export SCREEN_STATE="extended"

        function screenToggle() {
        if [[ $SCREEN_STATE == "extended" ]]; then
        xrandr --output eDPI1 --output HDMI1 --same-as eDPI1
        export SCREEN_STATE="mirrored"

        else
        xrandr --output eDPI1 --output HDMI1 --left-of eDPI1
        export SCREEN_STATE="extended"

        fi
        }


        Note that I haven't tested this code and on the first run, the displays will go to mirror mode due to the second line and you can't change that behaviour.



        For more values that you may need to pass to control the resolution see man xrandr and this similar question.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 at 8:53

























        answered Nov 20 at 8:48









        ArchNoob

        1,0011228




        1,0011228






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388510%2fextended-to-duplicate-monitor-script-without-function-key%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

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen