#Does xinput not work in an acpi event script?

5 messages Β· Page 1 of 1 (latest)

buoyant terrace
#

I'm making a script to disable my mouse when the screen closes because that was causing the laptop to wake up while closed and waste power. It is successfully putting the laptop back to sleep when it awakes while closed, but it isn't disabling the mouse. The script:


#!/bin/bash
#β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
#β”‚Solves the problem of laptop waking    β”‚
#β”‚up while suspended due to getting inputβ”‚
#β”‚from the mouse                         β”‚
#β”‚                                       β”‚
#β”‚Needs to be set up with ACPI to start  β”‚
#β”‚when the lid closes                    β”‚
#β”‚                                       β”‚
#β”‚Should not run while the laptop is in  β”‚
#β”‚use, only when the lid is closed       β”‚
#β”‚                                       β”‚
#β”‚v1                                     β”‚
#β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

# xinput list
# then, find your mouse id and put it here
# possibly when you plug in more devices this changes
device=9

# use whereis to make sure these paths are right
cat=/usr/bin/cat
grep=/usr/bin/grep
xinput=/usr/bin/xinput
systemctl=/usr/bin/systemctl
sleep=/usr/bin/sleep

# might be LID instead of LID0 or some other place entirely
# script depends on this file containing "open" when open
lidstate=/proc/acpi/button/lid/LID0/state

while :; do
    $cat $lidstate | $grep open
    if [ $? -ne 0 ]; then
        # lid closed
        /usr/bin/echo helloworld >>/tmp/lid-close-log
        $xinput list >>/tmp/lid-close-log
        $xinput disable $device
        $systemctl suspend
    else
        # lid open
        $xinput enable $device
        exit
    fi
    $sleep 1
done

I'm printing the result of xinput list into a text file to try to figure out the issue, but nothing is printed into that text file other than the helloworld. I think there is something stopping xinput commands from working properly. can someone help me out with this? i cant figure out the issue

buoyant terrace
#

Figured it out

#

env | grep DISPLAY and env | grep XAUTHORITY

#

then take whatever you get from that and export those values at the top of the script

#

will look like

export DISPLAY=:0
export XAUTHORITY=/home/myname/.Xauthority