43
submitted 17 hours ago by trymeout@lemmy.world to c/linux@lemmy.ml

I created a simple Bash script that will always disable the default/internal monitor on your laptop when using AR glasses (or any other external monitor). 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 interal laptop display to become enabled.

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

Simply copy this script and create a new bash script such as disable-display.sh, make the script file executable and add it to your startup applications 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 variable names in the script accordingly.

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

Enjoy

#!/bin/bash

#RUN xrandr TO GET THE NAMES OF THE DISPLAYS AND SET THE VARIABLES TO THESE NAMES

readonly default_display="eDP"
readonly external_display="USB-C-0"

readonly wait=5

while true; do
    #Check if there is an external display connected
    if xrandr | grep -q "$external_display connected"; then
        #Disable the internal display
        xrandr --output $default_display --off
    fi

    sleep $wait
done
you are viewing a single comment's thread
view the rest of the comments
[-] oshu@lemmy.world 3 points 16 hours ago* (last edited 16 hours ago)

Serious question, why use a semicolon to put do and then on the end of the previous line?

Especially when do/done are the open and close control directives for a block.

Don't you think bash looks much cleaner when you use it how it was designed?

[-] smeg@feddit.uk 2 points 3 hours ago

I'd write

while true; do
    X
done

for the same reason I'd write

if [ something ]; then
    X
fi

or in another language

if (something) {
    X
}

Because it's all part of the same statement and having a single line with just do or { seems silly and implies (to me) that the lines aren't related.

[-] tasankovasara@sopuli.xyz 5 points 8 hours ago

In defense of OP, I do this a lot and go for similar moves in other languages too if the conditional bit is just a line or two. Pro choice!

[-] LiveLM@lemmy.zip 7 points 12 hours ago

Bash doesn't ever look clean.

[-] QuazarOmega@lemy.lol 10 points 16 hours ago

It's just a brace on same line/new line stylistic choice with extra steps.
About that, I used to also think that brace on new line is clearer, but after seeing a lot more code I have switched sides, both are clear enough to me, so I'd rather have fewer lines

[-] oshu@lemmy.world 1 points 6 hours ago

Yes totally a personalstyle choice. To me, using a semicolon to save a line looks more ugly ; then ;)

[-] theit8514@lemmy.world 2 points 16 hours ago* (last edited 16 hours ago)

Not OP but this is how I learned it and how it's presented in the help file.

$ help while
while: while COMMANDS; do COMMANDS-2; done

$ help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
[-] oshu@lemmy.world 1 points 16 hours ago

Thats the concise help text to keep it short and easy to read.

The first line in the GNU Bash manual section on loop constructs says "Note that wherever a ‘;’ appears in the description of a command’s syntax, it may be replaced with one or more newlines."

this post was submitted on 14 May 2025
43 points (100.0% liked)

Linux

54171 readers
787 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS