Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Yes it does, I am 100% sure. – vitiv Sep 12 '12 at 8:33
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

Since the accepted answer doesn't work on my system here is a udev rule that works with gnome/gdm v. 3.16.2 and udev/systemd v. 226:

ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", \
ATTRS{bInterfaceSubClass}=="01", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", \
ENV{DISPLAY}=":0", ENV{REMOVE_CMD}="/usr/bin/xinput --enable 'SynPS/2 Synaptics TouchPad'", \
RUN+="/usr/bin/xinput --disable 'SynPS/2 Synaptics TouchPad'"

ENV{REMOVE_CMD} is the command used when the device is removed.
SynPS/2 Synaptics TouchPad is the name of the touchpad device as reported by xinput.
The UID used in ENV{XAUTHORITY} (e.g. 1000 in my rule) has to match your user ID.
Note the backslashes at end of lines are needed, as otherwise udev rules cannot span over multiple lines. If you prefer in one line:

 ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", ATTRS{bInterfaceSubClass}=="01", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", ENV{REMOVE_CMD}="/usr/bin/xinput --enable 'SynPS/2 Synaptics TouchPad'", RUN+="/usr/bin/xinput --disable 'SynPS/2 Synaptics TouchPad'"
share|improve this answer

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.