I have been using a udev rule to detect external mouse's pluging/unpluging, then based on the information to disable/enable the touchpad. The manual command is:
$ synclient TouchpadOff=0 # or
$ synclient TouchpadOff=1

It didn't work for months, the message from udevd looks like:
[5486] util_run_program: '/usr/bin/synclient TouchpadOff=1'
[5486] util_run_program: '/usr/bin/synclient' (stderr) 'Failed to connect to X Server.'
[5486] util_run_program: '/usr/bin/synclient' returned with status 1

I finally decided to look into it. I didn't track synclient's updates, but I guess some time ago, it began to use device properties by default, instead of SHM.
$ synclient 
Usage: synclient [-s] [-m interval] [-h] [-l] [-V] [-?] [var1=value1 [var2=value2] ...]
-s Use SHM area instead of device properties.
[snip]

So, you need to use -s if you need to control the touchpad parameter from the user account other than the one runs X Window via SHM (You need SHMConfig to be enabled, read the post below via link), says root account if your udevd is run by root.

It's easy to fix your rule, just put -s on. I have two lines in /etc/udev/rules.d/99-synaptics.rules:
ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="/usr/bin/synclient -s TouchpadOff=1"
ACTION=="remove", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="/usr/bin/synclient -s TouchpadOff=0"

Easy to fix, but it took me months to do it.

PS. If you are also interested in using HAL to set up touchpad parameters, please read my old post, Proper way to turn on SHMConfig in X Server 1.5 with input hotplugging.