Skip to content

Instantly share code, notes, and snippets.

@jmkelly
Last active November 24, 2024 04:35
Show Gist options
  • Save jmkelly/809ae0c941ee0ef71c7301b4c27e3161 to your computer and use it in GitHub Desktop.
Save jmkelly/809ae0c941ee0ef71c7301b4c27e3161 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Replace these values with your actual setup
DISPLAY_NAME="HDMI-1"
WIDTH=2560
HEIGHT=1080
CUSTOM_MODE_NAME="${WIDTH}x${HEIGHT}"
# Check if the display is connected
if xrandr | grep -q "$DISPLAY_NAME disconnected"; then
echo "$DISPLAY_NAME is not connected!"
exit 1
fi
# Use cvt to generate modeline data
MODELINEDATA=$(cvt $WIDTH $HEIGHT | grep Modeline | cut -d' ' -f4-)
# Add custom mode
if ! xrandr --newmode "$CUSTOM_MODE_NAME" $MODELINEDATA; then
echo "Failed to create the new mode."
exit 1
fi
# Add mode to display
if ! xrandr --addmode $DISPLAY_NAME "$CUSTOM_MODE_NAME"; then
echo "Failed to add the mode to the display."
exit 1
fi
# Apply the new resolution
if ! xrandr --output $DISPLAY_NAME --mode "$CUSTOM_MODE_NAME"; then
echo "Failed to apply the new resolution."
exit 1
fi
echo "Successfully applied the custom resolution $CUSTOM_MODE_NAME to $DISPLAY_NAME."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment