Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    1

    Question 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 uses
    Code:
    if xinput list '2.4G Wireless Mouse';
    to 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?

    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
    Code:
    xinput list | fgrep '2.4G Wireless Mouse' |sed -e s/.*id=//
    . This returns the number, but also the rest of the line e.g. 10 [slave pointer (2)]

    I want to remove everything after the number so that the command would return 10
    Last edited by mom2twinzz; 08-30-2011 at 10:48 PM. Reason: To add code I have

  2. #2
    Linux 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|'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...