I'm trying to program a non-working special key on my keyboard using the acpi events, and already got acpi to recognize a keypress and pass it on to a shell script. However, for some reason I cannot execute a call to xinput; it always returns with an exit code of 1 and no output. When running the shell script manually it works.

I've also noticed that if I call xinput --version I get a correct result calling manually, but when it's called through the acpi, it returns exit code 1 and Server: failed to open display, so I guess these are related in some way.

My bash script is quite easy at this moment, but if I can't call xinput, it's rather worthless (as I need to be able to enable/disable using xinput commands).


if [ "$3" != $touch ]; then
    # Ignore, not a touchpad event
    echo "$3 is not matching $touch, ignoring"
    exit 0  

# Process event
echo "Got a touchpad keypress"

    # extract the device id for the supplied touch device name
    xinput list | sed -nr "s|.*$1.*id=([0-9]+).*|\1|p"

ENABLEPROP="Device Enabled"
# Get the xinput device number and enabling property for the touchpad
XINPUTNUM=$(getTouchDeviceId "PS/2 Elantech Touchpad")

# Removed the rest

I've double checked a lot of things (environment should be ok, it can find the executable), and I know that the code was working at some point (it's based on the code that shipped in Ubuntu in the past.

A whoami in the script revealed that it's ran as root, while the desktop environment probably is linked to my regular user account, but I'm not sure how I could fix that...

Edit: When running the xinput as root from a terminal (or running the shell manually as root), it works. When it's called as root through the script activated by the acpi, it's not working.

Would anyone have a suggestion how I could fix this?


xinput needs the DISPLAY and XAUTHORITY env variables. 'export' these at the top of the script.

  • Thank you! This was effectively what I needed to get it working. – canihavesomecoffee Oct 18 '15 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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