xrandr script for external monitor adjustment not executing from udev

Spread the love

My laptop has a 4k screen and I also have an external 1080p monitor. The scaling is incorrect on the monitor and so every time I plug in the monitor, I execute an xrandr command to fix it. I figured I could automate the process and have created a udev rule to execute when it recognizes my monitor is plugged into the HDMI port. The issue is that the xrandr scripts are not being executed. I put an echo to a text file in the script right above the xrandr command to make sure it was reaching that point and it was. I have also tried using sleep commands, but the external monitor just waits for the script to finish sleeping before turning on. Running the script manually works.
My udev rule file is as follows:
SUBSYSTEM==”drm”, ACTION==”change”, RUN+=”/usr/local/bin/ext_monitor_scale”

xrandr script:
USER_NAME=`who | grep “(:0)” | cut -f 1 -d ‘ ‘`
HDMI_STATUS=`cat /sys/class/drm/card0/card0-DP-3/status`

if [ $HDMI_STATUS = “connected” ]
echo “test” >> test.txt
sudo -u $USER_NAME xrandr –output DP-3 –scale 2×2 –output eDP-1 –scale 0.9999×0.9999

Does anyone know a workaround? It seems I need to wait and allow the monitor to come on incorrectly and then have the script execute the xrandr command, but since the display waits for sleep before it auto adjusts I don’t know how to go about this. Thanks!

X ITM Cloud News


Leave a Reply

Next Post

What are the exact steps to install a 2-disk RAID 1 Desktop Ubuntu 20.04 system?

Fri Sep 11 , 2020
Spread the love          I am trying to install a Desktop Ubuntu 20.04 with RAID 1 on a PC that has two hard disks of the same size. I cannot find the dialog in the installer that matches the documentation I read on the subject. The Ubuntu page https://ubuntu.com/server/docs/installation-advanced says “Follow the […]

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware