Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am pretty new to udev and wanted to write a rule that upon connecting an usb mouse disables my touchpad.

This is what I have come up with(mostly by ear):

ACTION=="add", SUBSYSTEM=="input", ENV{ID_MODEL}=="USB_Mouse", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/nikitautiu/.Xauthority", ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=0", RUN+="/usr/bin/synclient TouchpadOff=1"

Nonetheless it doesn't trigger the desired effect. The command seems to be fine though the rule does not trigger when connecting my usb mouse.

share|improve this question
Does /usr/bin/synclient TouchpadOff=1 work as expected when run from terminal ? Also, are you using a display manager like GDM ? –  don_crissti Sep 11 '12 at 20:49
Yes it does, I am 100% sure. –  vitiv Sep 12 '12 at 8:33

1 Answer 1

up vote 2 down vote accepted

I don't grasp why your rule is so complex? Especially this section

ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=0"

In the first line you match the environment variable ID_MODEL which is only seen by udev against USB_Mouse. In the following three lines you assign values to environment variables. Again only seen by udev and the executed command synclient if the rule is applied.

I'm pretty sure that this rule is never applied (You can check this by parsing udev's log file.) since it is likely that there is no variable ID_MODEL with content USB_Mouse accessible unless you set ID_MODEL in the udev environment previously.

I suggest that you match against the Action, the vendor-ID and the product-ID of your mouse, which will suffice in most cases. Then your rule looks like

ACTION=="add", ATTRS{idVendor}=="<idVendor>", ATTRS{idProduct}=="<idProduct>", RUN+="/usr/bin/synclient TouchpadOff=1"

You can get <idVendor> and the <idProduct> by parsing the output of

lsusb -v

I don't remember if the given hex-values are allowed in the classical form 0xffff. I always take only the part behind 0x in my rules.

share|improve this answer
Well it works, but this is vendor or product dependant. Isn't there any attr or env varaible to identify a usb mouse by? PS: It's hex by default, no need for 0x –  vitiv Sep 12 '12 at 8:02
A more generic approach would be to match against ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", ATTRS{bInterfaceSubClass}=="01". These are specific characteristics for a usb mouse. For further information see lsusb -v and usb.org/developers/defined_class. –  user1146332 Sep 12 '12 at 9:02
Exactly what I was looking for, thanks! –  vitiv Sep 12 '12 at 9:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.