You are not logged in.

#1 2014-08-25 20:31:32

wmunny
Member
Registered: 2014-08-25
Posts: 4

[SOLVED] acpid lid close script

hy guys im having a bit of had ack here i have this script here:

#!/bin/bash

xrandr | grep DP- | grep " connected ";
if [ $? -eq 0 ]; then
   echo "other screens connected" 
else
        pm-suspend
fi

and i placed this script to run here :

button/lid)
        case "$3" in
            close)
                logger 'LID closed'
                                suspend.sh
                ;;
            open)
                logger 'LID opened'
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
    esac

my problem is the script runs properly if i execute it as (user or root)
but when i do close the lid and the script acpid execute it for some reason that i dont know it dont get the extra screens and suspend anyway

some one could point me the error here ??


thanks on advance

Last edited by wmunny (2014-08-26 00:20:22)

Offline

#2 2014-08-25 20:48:16

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] acpid lid close script

The difference is probably the DISPLAY variable being ":0.0", versus unset.

Try adding, before the xrandr line in your script:

export DISPLAY=":0.0"

Offline

#3 2014-08-25 20:49:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,346

Re: [SOLVED] acpid lid close script

Did you disable the lid detect logic in systemd?
Are you sure that the acpi deamon is running?

Edit:  BTW, Welcome to Arch Linux smile

Last edited by ewaller (2014-08-25 20:50:44)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2014-08-25 20:57:17

wmunny
Member
Registered: 2014-08-25
Posts: 4

Re: [SOLVED] acpid lid close script

ewaller

yes i did ignore lid on logind
and apci is running


brebs

that didn't work

Offline

#5 2014-08-25 20:59:53

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] acpid lid close script

OK, next step: Redirect the output of those commands somewhere useful, e.g.:

xrandr >> /tmp/x.log 2>&1

Offline

#6 2014-08-25 21:04:04

wmunny
Member
Registered: 2014-08-25
Posts: 4

Re: [SOLVED] acpid lid close script

looks like you are right :

Can't open display :0.0

but i still have no idea how to fix it

Last edited by wmunny (2014-08-25 21:08:39)

Offline

#7 2014-08-25 22:42:32

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [SOLVED] acpid lid close script

xrandr | grep DP- | grep " connected ";
#can be reduced to
xrandr | grep 'DP-.* connected';

You could also include whoami and env in the log.

 Why are you running this through a script? Those few lines could be left in the handler, you modified the file anyway.

Last edited by emeres (2014-08-25 22:43:11)

Offline

#8 2014-08-25 23:48:08

wmunny
Member
Registered: 2014-08-25
Posts: 4

Re: [SOLVED] acpid lid close script

ok guys i finally got a fix here
using this changes:

 #!/bin/bash
 user="$(who -u | grep -F '(:0)' | head -n 1 | awk '{print $1}')"
 su -c "DISPLAY=:0.0 xrandr | grep DP- | grep ' connected '" "$user";
 if [ $? -eq 0 ]; then
     echo "worked" >> /tmp/x.log 2>&1
 else
     pm-suspend
 fi

on the script did the trick thanks everyone

Last edited by wmunny (2014-08-26 00:20:31)

Offline

#9 2014-08-26 00:17:44

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [SOLVED] acpid lid close script

user="$(who -u | grep -F '(:0)' | head -n 1 | awk '{print $1}')"
#can be reduced to
user="$(who -u | awk '/(:0)/{print $1; exit}')"

Forum etiquette - how to post.

Offline

#10 2014-08-26 05:56:51

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] acpid lid close script

I forgot - XAUTHORITY is needed, as well as DISPLAY.

Your normal user has *both* of these set, which is why using su works.

Offline

Board footer

Powered by FluxBB