Skip to content

Instantly share code, notes, and snippets.

@Alynva
Last active November 24, 2024 22:44
Show Gist options
  • Save Alynva/2c5cbdd79c429630020be6ba3a530a1b to your computer and use it in GitHub Desktop.
Save Alynva/2c5cbdd79c429630020be6ba3a530a1b to your computer and use it in GitHub Desktop.
Raspberry HDMI auto detect and update resolution
#!/bin/bash
# sudo nano /etc/udev/rules.d/99-hdmi-hotplug.rules
# ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/local/bin/hdmi_hotplug.sh"
# sudo udevadm control --reload-rules
logger "Display changed."
export DISPLAY=:0
status=$(xrandr | grep 'HDMI-1' | awk '{print $2}')
logger "C: $status"
if [ "$status" == "connected" ]; then
export DISPLAY=:0
# Run xrandr to reconfigure the display
xrandr --output HDMI-1 --auto 2>&1 | logger
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment