The scripts returns (echos) xinput id of a pointing device by its name, and if the name is not unique also by its USB interface number.
It is suggested to set the script mode to grant execute permissions.
| Name | Position | Mandatory | Default value | Description |
|---|---|---|---|---|
DEVICE_NAME |
1 | yes | The device name as reported by xinput list. |
|
DEVICE_NUM |
2 | optional | 0 |
The device USB interface number: udev's bInterfaceNumber / ID_USB_INTERFACE_NUM value.If the value is one character (digit) only, then it is left padded with 0. |
flags:-f or --force |
last | optional | absent | If the flag is present, always compare DEVICE_NUM value, even if there is only one device with DEVICE_NAME. |
Both DEVICE_NAME and DEVICE_NUM values can be passed either as positional arguments, or in front in the form of environment variables.
0on success: xinput id is returned.1otherwise:DEVICE_NAMEis empty or not listed byxinput list, orDEVICE_NUMdoes not match anyudev'sbInterfaceNumber/ID_USB_INTERFACE_NUMvalue.
mouse_id=$(DEVICE_NAME="Razer Razer DeathAdder V2 X HyperSpeed" ./get_pointer_id.sh)./get_pointer_id.sh "Razer Razer DeathAdder V2 X HyperSpeed" 1 -f; echo -e "\nExit code: $?"- The script should also work for keyboard devices if you replace every
pointercharacter string withkeyboardin allbash/grep/perl/awk/sedregular expressions, but I have not tested it yet. DEVICE_NAME(andDEVICE_NUM) values are stripped, and all whitespace sequences are replace with a single space character (U+0020: ''). If this behaviour is unwanted, simply delete allstr_stripfunction invocations.
If you are not sure what the right DEVICE_NUM value is for your pointing device, follow the instructions:
- Execute
xinput list --shortand note down all you device'sidvalues ({device_id}hereinafter). - For every
{device_id}, find itsDevice Nodevalue withxinput --list-props {device_id}. The outcome should be likeDevice Node (278): "/dev/input/event20".
You can also ease it with the following snippet extracted from thename_by_idfunction:
xinput --list-props {device_id} | awk 'BEGIN{FS=":[ \t]*"}/^[ \t]*Device Node \(/ {print substr($2, 2, length($2)-2)}'- Use the
catcommand to open the sysfsDevice Nodefile. For example:
cat /dev/input/event20- Move the mouse, and then terminate
catwithCtrl+C. If you could observe some characters being printed out to the terminal, it is very likely you have found correctDevice Node. Otherwise, please repeat steps2.,3., and4.for the next{device_id}value. - Find
Device Node'sID_USB_INTERFACE_NUMvalue withudevadm info --query=property --name={Device Node}. The outcome should be likeID_USB_INTERFACE_NUM=00, and these digits are precisely yourDEVICE_NUMvalue. If it is00, then you are good to go with the script's defaultDEVICE_NUMargument value.
You can also use the following snippet extracted from theis_usb_intfnum_by_idfunction:
udevadm info --query=property --name={Device Node} | awk 'BEGIN{FS="="}/^[ \t]*ID_USB_INTERFACE_NUM/ {print $2}'