Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

write bash script to turn off integrated monitor if HDMI is connected

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-2025-04-14’s answer.
  1. User

    write bash script to turn off integrated monitor if HDMI is connected

  2. Claude Assistant
    #!/bin/bash
    
    # Check if xrandr command exists
    if ! command -v xrandr &> /dev/null; then
        echo "xrandr command not found. Please install it first."
        exit 1
    fi
    
    # Function to detect if HDMI is connected
    is_hdmi_connected() {
        xrandr | grep "HDMI" | grep " connected " > /dev/null
    }
    
    # Function to get the internal display name
    get_internal_display() {
        # Common names for internal displays
        for display in eDP eDP-1 eDP1 LVDS LVDS-1 LVDS1; do
            if xrandr | grep -w "$display connected" > /dev/null; then
                echo "$display"
                return
            fi
        done
        
        # If no common name found, try to identify the non-HDMI connected display
        xrandr | grep " connected " | grep -v "HDMI" | head -1 | awk '{print $1}'
    }
    
    # Function to get the HDMI display name
    get_hdmi_display() {
        # Find the first connected HDMI display
        xrandr | grep "HDMI" | grep " connected " | head -1 | awk '{print $1}'
    }
    
    # Main script
    INTERNAL_DISPLAY=$(get_internal_display)
    
    if [ -z "$INTERNAL_DISPLAY" ]; then
        echo "Could not identify internal display."
        exit 1
    fi
    
    if is_hdmi_connected; then
        HDMI_DISPLAY=$(get_hdmi_display)
        
        if [ -z "$HDMI_DISPLAY" ]; then
            echo "HDMI display detected but could not identify it."
            exit 1
        fi
        
        # Turn off the internal display, enable only the HDMI
        xrandr --output "$INTERNAL_DISPLAY" --off --output "$HDMI_DISPLAY" --auto
        echo "HDMI display ($HDMI_DISPLAY) connected. Turned off internal display ($INTERNAL_DISPLAY)."
    else
        # No HDMI connected, make sure internal display is on
        xrandr --output "$INTERNAL_DISPLAY" --auto
        echo "No HDMI display connected. Internal display ($INTERNAL_DISPLAY) enabled."
    fi
    

    Would you like me to explain or break down this code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.