Skip to content

Instantly share code, notes, and snippets.

@silashansen
Last active January 5, 2024 10:19
Show Gist options
  • Save silashansen/c139f8375066863e9ed86c22c70ee2d1 to your computer and use it in GitHub Desktop.
Save silashansen/c139f8375066863e9ed86c22c70ee2d1 to your computer and use it in GitHub Desktop.
Force RGB on MacOS
#!/bin/bash
fix_rgb() {
fixes=0
dryrun=false
if [ ! -t 0 ]; then
read -p "Do you want to proceed with fixing? (y/n): " answer
if [ "$answer" = "n" ]; then
dryrun=true
fi
fi
for plist in /Library/Preferences/com.apple.windowserver.displays.plist ~/Library/Preferences/ByHost/com.apple.windowserver.displays.*.plist; do
original=$(mktemp)
patched=$(mktemp)
cp "$plist" "$original"
plutil -convert json "$original"
jq --argjson LinkDescription '{"Range":1,"BitDepth":8,"EOTF":0,"PixelEncoding":0}' '( .. | select(.CurrentInfo?) | .LinkDescription ) |= $LinkDescription' "$original" > "$patched" 2>/dev/null
echo 'null' | jq --argfile original "$original" --argfile patched "$patched" 'if $original != $patched then halt_error(99) else empty end'
if [ ! $? -eq 0 ]; then
filename="$plist"
if $dryrun; then
echo -e "$filename need to be fixed"
diff --color=always --side-by-side <(jq -S '.' "$original") <(jq -S '.' "$patched")
else
echo -e "Fixing $filename"
fi
fixes=$((fixes + 1))
if ! $dryrun; then
plutil -convert binary1 "$patched"
if [[ "$plist" == "$HOME/"* ]]; then
cp "$plist" "$plist.bak"
chflags nouchg "$plist"
cp "$patched" "$plist"
chflags uchg "$plist"
else
sudo cp "$plist" "$plist.bak"
sudo chflags nouchg "$plist"
sudo cp "$patched" "$plist"
sudo chflags uchg "$plist"
fi
fi
fi
done
if [ $fixes -gt 0 ]; then
echo -e "$fixes files fixed. Log out BEFORE rebooting your Mac to apply changes."
else
echo "Your Mac is already set."
fi
}
fix_rgb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment