2

See SOLUTION at the end.

I have used this guide to write a script that activates when I open or close the laptop lid. My setup is a laptop monitor and an external monitor working well together.

Basically (everything works fine the first 3 steps, the confusion starts on step 4):

1) I have created the ~/export_x_info file about permission issues and running it on startup containing:

# Export the dbus session address on startup so it can be used by any other environment
sleep 5
touch $HOME/.Xdbus
chmod 600 $HOME/.Xdbus
env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus
# Export XAUTHORITY value on startup so it can be used by cron
env | grep XAUTHORITY >> $HOME/.Xdbus
echo 'export XAUTHORITY' >> $HOME/.Xdbus

2) I created /etc/acpi/lid.sh pointing to the actual script on my home directory containing these two lines:

#!/bin/bash
/home/myname/scripts/lid_event

3) On the lid_event I put the following:

grep -q closed /proc/acpi/button/lid/LID/state
if [ $? = 0 ]
then
    /home/myname/scripts/close;
else
    /home/myname/scripts/open;
fi

Until now everything is as expected. I have checked the "/proc/acpi/button/lid/LID/state" file and changes depending on lid being open or closed. All files I have created are executable so there is no problem there.

4) On my "close" script I have this ("open" script is similar so no need to mention it):

 #This runs so that root can run the following command under the user's environment
source /home/myname/.Xdbus

#When laptop lid closes, close laptop screen.
DISPLAY=:0.0 su myname -c xrandr --output eDP1 --off

When I close the lid I want the laptop screen to close and have only the VGA screen up. The above command works great when manually executing it at the terminal or manually executing this script but when it's about ACPI it does not execute!

Now, the weird thing is if I put a simple command like "touch ~/file" on the above script, it executes perfectly!

It seems to be a specific problem with xrandr. I suspect that there might be some permission issues unresolved but I cannot find a solution.

terdon
  • 100,812
user2832080
  • 261
  • 4
  • 8
  • It is hard to find your solution when you put it in the question and this does not follow Ask Ubuntu guides. Please, create an answer for that, see http://askubuntu.com/help/self-answer . You can accept it afterward. :) you gonna collect more rep this way. – user.dz Sep 06 '15 at 21:14

2 Answers2

2

SOLUTION

It seems that the info on the ubuntu community is not complete. You need to make one more step in order to work. According to this, you additionally need to create /etc/acpi/events/lm_lid and put:

event=button/lid.*
action=/etc/acpi/lid.sh

Now it works fine for me. I have updated the Ubuntu guide so you can safely follow the guide here

user2832080
  • 261
  • 4
  • 8
  • 1
    Thanks for posting the answer! If you could remember to come back and accept it, that would be great. – terdon Sep 07 '15 at 12:29
0

You need to quote the command that su is to run so it is one string:

DISPLAY=:0.0 su myname -c 'xrandr --output eDP1 --off'
meuh
  • 3,211
  • Unfortunately, it still does not work! – user2832080 Sep 06 '15 at 20:33
  • Thanks for the help. The main problem was that I needed to create one more acpi file that wasn't included in the ubuntu guide. Of course that alone wouldn't work if I didn't put "" at the commands! – user2832080 Sep 06 '15 at 20:52