Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:56:58+00:00 2026-06-17T01:56:58+00:00

I wrote a small shell script configuring attached external displays with xrandr. # cat

  • 0

I wrote a small shell script configuring attached external displays with xrandr.

# cat /home/didi/bin/monitor_autoswitcher.sh 
#!/bin/bash

xrandr | grep "HDMI1 connected"
if [[ $? == 0 ]]; then
  # is connected
  xrandr --output HDMI1 --right-of LVDS1 --auto
else
  # not connected
  xrandr --output HDMI1 --auto
fi

xrandr | grep "VGA1 connected"
if [[ $? == 0 ]]; then
  # is connected
  xrandr --output VGA1 --right-of LVDS1 --auto
else
  # not connected
  xrandr --output VGA1 --auto
fi

That works. Now I want to have it triggered automatically and found out that this can be done with udev.
I tried

udevadm monitor

which, when plugging in an external displays outputs

KERNEL[465828.240250] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [465828.243549] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)

and when plugging it out

KERNEL[465836.844209] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [465836.847445] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)

Also good.

Then I added an udev rule:

# cat 40-external-display.rules 
SUBSYSTEM=="drm", ACTION=="change", RUN+="/home/didi/bin/monitor_autoswitcher.sh"

and restarted udev

service udev restart

Unfortunately, still nothing happens when plugging in/out the display. The script monitor_autoswitcher.sh definitely works, because invoking it manually after plugging does what it should.

What’s missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:56:59+00:00Added an answer on June 17, 2026 at 1:56 am

    This looks like pretty much the same thing. The only real difference I see is that the script sets the DISPLAY variable, which may be key.

    http://ruedigergad.com/2012/01/28/hotplug-an-external-screen-to-your-laptop-on-linux/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small shell script based on an example I found here: https://bbs.archlinux.org/viewtopic.php?id=36305
I have shell scripting knowledge. I have written a small shell script which will
I'm currently trying to make some small shell-like utility for a custom script I
I am new to Shell script. Just have a small question about some script
I wrote a small script to help re-organize my .mp3 collection. When I run
I wrote a very small application, which access the Remote Power Shell of Exchanger
I have a small shell script in a string inside my python file. Now
I wrote a small express.js based web app. I serve a manifest.webapp but express.js
I wrote two small applications (a client and a server) to test UDP communication
I wrote a small test program for flipperview. I have 3 views. I call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.