Results 1 to 2 of 2
Because I have a laptop and don't always use the touchpad, i have come across a problem that I have no idea how to fix. I have a script that ...
- 08-30-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 1
Bash script help
Because I have a laptop and don't always use the touchpad, i have come across a problem that I have no idea how to fix. I have a script that is supposed to snap windows to the sides (like Windows 7 does), however it uses the id number from xinput. But since I use a mouse sometimes, that number can change on the fly.
Because I have a script that disables the touchpad completely if the mouse is plugged in, that usesto determine if the mouse is discovered, I know that I could likely find the id using the same logic, but that's where my question lies. How would I use the xinput list command with the same '2.4G Wireless Mouse' string to return the id, so it can dynamically change the number as needed?Code:if xinput list '2.4G Wireless Mouse';
I am still trying to learn to script, so using someone else's code and customizing is still difficult.
Edit:
So far the code I have is. This returns the number, but also the rest of the line e.g. 10 [slave pointer (2)]Code:xinput list | fgrep '2.4G Wireless Mouse' |sed -e s/.*id=//
I want to remove everything after the number so that the command would return 10Last edited by mom2twinzz; 08-30-2011 at 10:48 PM. Reason: To add code I have
- 08-31-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
match on numbers after the "=" sign, and "remember" it (for variable substituting) using parentheses, and strip out trailing stuff:
Code:xinput list | fgrep '2.4G Wireless Mouse' | sed -e 's|^.*id=\([0-9]*\).*$|\1|'


Reply With Quote