Skip to content

Instantly share code, notes, and snippets.

@QuanTrieuPCYT
Last active April 19, 2026 07:54
Show Gist options
  • Select an option

  • Save QuanTrieuPCYT/8e1f42915715f4837e029d8cedd73b06 to your computer and use it in GitHub Desktop.

Select an option

Save QuanTrieuPCYT/8e1f42915715f4837e029d8cedd73b06 to your computer and use it in GitHub Desktop.
Auto-switch between 120Hz and 60Hz when plugged in on MacBook Pro 14-inch running Asahi Linux
#!/bin/bash
DISPLAY_NAME="eDP-1"
PLUGGED="3024x1964@120"
UNPLUGGED="3024x1964@60"
toggle() {
if grep -q "1" /sys/class/power_supply/*/online 2>/dev/null; then
kscreen-doctor output."$DISPLAY_NAME".mode."$PLUGGED"
else
kscreen-doctor output."$DISPLAY_NAME".mode."$UNPLUGGED"
fi
}
toggle
udevadm monitor --subsystem-match=power_supply | while read -r event; do
sleep 1
toggle
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment