Script to toggle laptop track pad

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















I have a script that disables the touchpad on my thinkpad:



#!/usr/bin/env bash

xinput --disable 12


How could I adjust the script so that instead of just disabling, it will check the current state of the touchpad and toggle the enable/disable?










share|improve this question

















  • 1





    xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

    – FrontENG
    Jul 15 '17 at 0:54
















2















I have a script that disables the touchpad on my thinkpad:



#!/usr/bin/env bash

xinput --disable 12


How could I adjust the script so that instead of just disabling, it will check the current state of the touchpad and toggle the enable/disable?










share|improve this question

















  • 1





    xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

    – FrontENG
    Jul 15 '17 at 0:54














2












2








2








I have a script that disables the touchpad on my thinkpad:



#!/usr/bin/env bash

xinput --disable 12


How could I adjust the script so that instead of just disabling, it will check the current state of the touchpad and toggle the enable/disable?










share|improve this question














I have a script that disables the touchpad on my thinkpad:



#!/usr/bin/env bash

xinput --disable 12


How could I adjust the script so that instead of just disabling, it will check the current state of the touchpad and toggle the enable/disable?







shell-script xinput






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 14 '17 at 23:08









SimonSimon

1112




1112







  • 1





    xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

    – FrontENG
    Jul 15 '17 at 0:54













  • 1





    xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

    – FrontENG
    Jul 15 '17 at 0:54








1




1





xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

– FrontENG
Jul 15 '17 at 0:54






xinput list shows a list all available and attached input devices on your system.Your current device should have id=12 section in its description.You may first show the STATE section then use an case statement to toggle between enable(state 0) disabled (state 1) URL for reference askubuntu.com/questions/65951/how-to-disable-the-touchpad

– FrontENG
Jul 15 '17 at 0:54











2 Answers
2






active

oldest

votes


















1














It's strange that xinput can't filter its output itself. But we have grep!



xinput --list-props 12 | grep -q 'Device Enabled.*1$' && echo enabled || echo disabled






share|improve this answer






























    0














    to toggle the touchpad you could run a perl one-liner from this script:



    perl -e '$dev="SynPS/2 Synaptics TouchPad"; `xinput list-props $dev` =~ /^.*Device Enabled.+?(d)$/m ; $1 ? `xinput --disable $dev` : `xinput --enable $dev`;


    short expanation:



    • the backticks execute a system/linux-command

    • while matching the line where it says "Device Enabled" the regex looks for the last numeric character on that line (which is 0 ... for off, or 1 ... for on)

    • the /m in the regex means: use each line from the output of the command as a seperate element (otherwise ^ and $ of the regex would mean the beginnen/end of the string, not the line

    • the parantheses save the matched number into the Variable $1

    • the rest is the ternary operaton: "if true" ? "do this" : "else to this", meaning if $1 equals 0 or 1 -> disable or enable

    (to use this in, e.g. "i3" window manager: you would have to write:



    bindsym XF86TouchpadToggle exec --no-startup-id perl -e '`xinput list-props 10` =~ /^.*Device Enabled.+?(d)$/m and $1 ? `xinput --disable 10` : `xinput --enable 10` '





    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',
      autoActivateHeartbeat: false,
      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%2f378571%2fscript-to-toggle-laptop-track-pad%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      It's strange that xinput can't filter its output itself. But we have grep!



      xinput --list-props 12 | grep -q 'Device Enabled.*1$' && echo enabled || echo disabled






      share|improve this answer



























        1














        It's strange that xinput can't filter its output itself. But we have grep!



        xinput --list-props 12 | grep -q 'Device Enabled.*1$' && echo enabled || echo disabled






        share|improve this answer

























          1












          1








          1







          It's strange that xinput can't filter its output itself. But we have grep!



          xinput --list-props 12 | grep -q 'Device Enabled.*1$' && echo enabled || echo disabled






          share|improve this answer













          It's strange that xinput can't filter its output itself. But we have grep!



          xinput --list-props 12 | grep -q 'Device Enabled.*1$' && echo enabled || echo disabled







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 12 '17 at 13:49









          L29AhL29Ah

          559114




          559114























              0














              to toggle the touchpad you could run a perl one-liner from this script:



              perl -e '$dev="SynPS/2 Synaptics TouchPad"; `xinput list-props $dev` =~ /^.*Device Enabled.+?(d)$/m ; $1 ? `xinput --disable $dev` : `xinput --enable $dev`;


              short expanation:



              • the backticks execute a system/linux-command

              • while matching the line where it says "Device Enabled" the regex looks for the last numeric character on that line (which is 0 ... for off, or 1 ... for on)

              • the /m in the regex means: use each line from the output of the command as a seperate element (otherwise ^ and $ of the regex would mean the beginnen/end of the string, not the line

              • the parantheses save the matched number into the Variable $1

              • the rest is the ternary operaton: "if true" ? "do this" : "else to this", meaning if $1 equals 0 or 1 -> disable or enable

              (to use this in, e.g. "i3" window manager: you would have to write:



              bindsym XF86TouchpadToggle exec --no-startup-id perl -e '`xinput list-props 10` =~ /^.*Device Enabled.+?(d)$/m and $1 ? `xinput --disable 10` : `xinput --enable 10` '





              share|improve this answer



























                0














                to toggle the touchpad you could run a perl one-liner from this script:



                perl -e '$dev="SynPS/2 Synaptics TouchPad"; `xinput list-props $dev` =~ /^.*Device Enabled.+?(d)$/m ; $1 ? `xinput --disable $dev` : `xinput --enable $dev`;


                short expanation:



                • the backticks execute a system/linux-command

                • while matching the line where it says "Device Enabled" the regex looks for the last numeric character on that line (which is 0 ... for off, or 1 ... for on)

                • the /m in the regex means: use each line from the output of the command as a seperate element (otherwise ^ and $ of the regex would mean the beginnen/end of the string, not the line

                • the parantheses save the matched number into the Variable $1

                • the rest is the ternary operaton: "if true" ? "do this" : "else to this", meaning if $1 equals 0 or 1 -> disable or enable

                (to use this in, e.g. "i3" window manager: you would have to write:



                bindsym XF86TouchpadToggle exec --no-startup-id perl -e '`xinput list-props 10` =~ /^.*Device Enabled.+?(d)$/m and $1 ? `xinput --disable 10` : `xinput --enable 10` '





                share|improve this answer

























                  0












                  0








                  0







                  to toggle the touchpad you could run a perl one-liner from this script:



                  perl -e '$dev="SynPS/2 Synaptics TouchPad"; `xinput list-props $dev` =~ /^.*Device Enabled.+?(d)$/m ; $1 ? `xinput --disable $dev` : `xinput --enable $dev`;


                  short expanation:



                  • the backticks execute a system/linux-command

                  • while matching the line where it says "Device Enabled" the regex looks for the last numeric character on that line (which is 0 ... for off, or 1 ... for on)

                  • the /m in the regex means: use each line from the output of the command as a seperate element (otherwise ^ and $ of the regex would mean the beginnen/end of the string, not the line

                  • the parantheses save the matched number into the Variable $1

                  • the rest is the ternary operaton: "if true" ? "do this" : "else to this", meaning if $1 equals 0 or 1 -> disable or enable

                  (to use this in, e.g. "i3" window manager: you would have to write:



                  bindsym XF86TouchpadToggle exec --no-startup-id perl -e '`xinput list-props 10` =~ /^.*Device Enabled.+?(d)$/m and $1 ? `xinput --disable 10` : `xinput --enable 10` '





                  share|improve this answer













                  to toggle the touchpad you could run a perl one-liner from this script:



                  perl -e '$dev="SynPS/2 Synaptics TouchPad"; `xinput list-props $dev` =~ /^.*Device Enabled.+?(d)$/m ; $1 ? `xinput --disable $dev` : `xinput --enable $dev`;


                  short expanation:



                  • the backticks execute a system/linux-command

                  • while matching the line where it says "Device Enabled" the regex looks for the last numeric character on that line (which is 0 ... for off, or 1 ... for on)

                  • the /m in the regex means: use each line from the output of the command as a seperate element (otherwise ^ and $ of the regex would mean the beginnen/end of the string, not the line

                  • the parantheses save the matched number into the Variable $1

                  • the rest is the ternary operaton: "if true" ? "do this" : "else to this", meaning if $1 equals 0 or 1 -> disable or enable

                  (to use this in, e.g. "i3" window manager: you would have to write:



                  bindsym XF86TouchpadToggle exec --no-startup-id perl -e '`xinput list-props 10` =~ /^.*Device Enabled.+?(d)$/m and $1 ? `xinput --disable 10` : `xinput --enable 10` '






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 5 at 12:48









                  elieli

                  658615




                  658615



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • 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%2funix.stackexchange.com%2fquestions%2f378571%2fscript-to-toggle-laptop-track-pad%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

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)