changing resolution from /etc/acpi/power.sh

Questions about hardware, drivers and peripherals
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
yhtomitwebb

changing resolution from /etc/acpi/power.sh

Post by yhtomitwebb »

Hi
I am trying to setup my system so that when I put my laptop onto the docking station if automatically enables my external monitor ( which is plugged into the docking station), the way that I am trying to do this is to add these lines to /etc/acpi/power.sh

Code: Select all

if xrandr -q | grep -q  "TMDS-1 connected"; then
	echo "enabling external display";
	exec xrandr --output LVDS --mode 1280x800 --output TMDS-1 --mode 1680x1050 --pos 0x0
else
	echo "disabling external display";
	exec xrandr --output LVDS --mode 1280x800 --pos 0x0 --output TMDS-1 --off
fi
This basically checks if the monitor is plugged in and if so enables it.
If I put those lines into a script and run the script manually, it works fine, but if I put those lines into /etc/acpi/power.sh it doesn't do anything at all.

I have checked that that /etc/acpi/power.sh actually gets run when power is plugged in or removed by adding this line to the file:

Code: Select all

echo "test" >> /home/timothy/Desktop/test.txt
and that works.

So has anyone got any idea on why this doesn't work?
Or how I could do it that does work?

thanks
Tim
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Husse

Re: changing resolution from /etc/acpi/power.sh

Post by Husse »

Can't test so a bit of guesswork
First off - I hope you have avoided getting it inside a function :)
Does it matter if it's added at the beginning or at the end?
It's not unusual however that scripts behave like this.
The separate script that works is that a bash script?
I don't really know what to look for in this case
And I hope you have a copy of the original file...
yhtomitwebb

Re: changing resolution from /etc/acpi/power.sh

Post by yhtomitwebb »

Sorry I haven't replied.
For all of those that have the same problem, this is how I fixed it (months later)

The problem it that the ACPI scripts do not have a connection to the X server and they are run as root, which by default is not allowed access to the X server.
I fixed it by making a script:

Code: Select all

#!/bin/bash
 
if xrandr -d :0 --screen 0 -q | grep -q  "TMDS-1 connected"; then
	exec xrandr -d :0 --screen 0 --output LVDS --off --output TMDS-1 --mode 1680x1050 --pos 0x0
else
	exec xrandr -d :0 --screen 0 --output LVDS --mode 1280x800 --pos 0x0 --output TMDS-1 --off
fi
and then putting into /etc/acpi/power.sh

Code: Select all

su [USER] -c [path to above script]
This then enables and disables my external monitor as it should

Hope this helps some one!
Tim
Locked

Return to “Hardware Support”