How to get synclient to set some options after a resume from suspend.

I had the problem that synclient would change my touchpad settings after a resume (specifically the clickpad settings). In order to fix it, I created a script which would call synclient and set the right settings and I called that script from a file in /etc/pm/sleep.d.

Unfortunately, that didn't work. Calling the script manually after the resume did, though.

After some investigation, I found this in /var/log/pm-suspend.log:

Failed to connect to X Server.

Obviously, synclient couldn't find the X server, so I googled a bit and tried the (quite obvious) fix of setting

export DISPLAY=':0'

This gave me:

No protocol specified
Failed to connect to X Server.

Some more googling led me to this ArchLinux thread and this Ubuntu thread. Applying those two solutions together yielded a working result:

  1. sleeping for two seconds (the script is already processed in the background, so the resume won't take longer!)
  2. running sh -c 'export -p' > env on a normal terminal and sourcing that env file before the call to synclient