Script to toggle laptop track pad

Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
shell-script xinput
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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` '
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Aug 12 '17 at 13:49
L29AhL29Ah
559114
559114
add a comment |
add a comment |
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` '
add a comment |
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` '
add a comment |
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` '
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` '
answered Feb 5 at 12:48
elieli
658615
658615
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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