cross-posted from: https://lemmy.world/post/48010802

I created a simple Nushell script that will always disable the default/internal monitor(s) on your laptop or external display when using AR glasses. I find this useful for when using AR glasses such as the XReal One which allows you to change the mode from regular mode to ultra-wide mode and when doing this, it will act as your unplugging the XReal ones and plugging in XReal one again in a new mode, causing the other display to become enabled.

To keep the laptop display always off, weather the laptop lid is either closed or open, this simple Nushell script will always disable the screen every X seconds (You can change it by changing the wait constant)

Simply copy this script and create a new Nushell script such as disable-displays.nu, add it to your startup applications with the command of nu /path/to/disable-displays.nu and it will run in the background. You will need to run xrandr command with all of your displays enabled to get the names of the displays and change the constants values in the script accordingly.

NOTE: This script may not work with a full Wayland setup and may only work on X11.

Enjoy

# RUN xrandr TO GET THE NAMES OF THE DISPLAYS AND SET THE VARIABLES TO THESE NAMES
const ar_glasses_display = 'USB-C-0'
const displays = [
    'eDP',
    'HDMI-0'
]

const wait = 5

def is-ar-glasses-connected [] {
    return (xrandr | str contains $"($ar_glasses_display) connected")
}

def disable-display [display: string] {
    xrandr --output $display --off
}

def enable-display [display: string] {
    xrandr --output $display --auto
}

loop {
    if (is-ar-glasses-connected) {
        for current_display in $displays {
            disable-display $current_display
        }
    } else {
        for current_display in $displays {
            enable-display $current_display
        }
    }

    sleep ($wait * 1sec)
}
    • trymeout@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      5
      ·
      edit-2
      1 hour ago

      If it cannot detect the glasses or if they are disconnected, it will restore the other displays. I have been using a similar version of the script for about a year that was written in Bash https://lemmy.world/post/29660071, I decided to rewrite it in Nushell since I prefer Nushell over Bash.

      Improvements are welcomed as this code is free for all to modify, share, and use