Skip to content

Instantly share code, notes, and snippets.

@krackers
Forked from ejdyksen/patch-edid.md
Created August 8, 2024 22:05
Show Gist options
  • Save krackers/4c720fa3077ba6d3ae5c0b2caea40e0f to your computer and use it in GitHub Desktop.
Save krackers/4c720fa3077ba6d3ae5c0b2caea40e0f to your computer and use it in GitHub Desktop.

Revisions

  1. @ejdyksen ejdyksen revised this gist Nov 16, 2020. 1 changed file with 20 additions and 33 deletions.
    53 changes: 20 additions & 33 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -1,53 +1,40 @@
    ## patch-edid.rb

    A script to fix EDID problems on external monitors in Mac OS.
    A script to fix EDID problems on external monitors in macOS.

    ### Additional reading

    * [The original forum thread](http://embdev.net/topic/284710)
    * An improved version of the script [by adaugherity](https://gist.github.com/adaugherity/7435890)
    * [An explaination of the problem](https://spin.atomicobject.com/2018/08/24/macbook-pro-external-monitor-display-problem/) from Atomic Object's blog

    ### Instructions

    ⚠️ **This requires disabling SIP, so run this at your own risk. Be sure to re-enable SIP at the end.**
    1. Connect only the problem display.

    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) while in [Recovery Mode](https://support.apple.com/en-us/HT201314). Reboot back into macOS when done.
    1. Create this directory structure (if it doesn't already exist):

    ```
    csrutil disable
    ```shell
    sudo mkdir -p /Library/Displays/Contents/Resources/Overrides
    ```

    1. For macOS Catalina and newer (which uses a [read-only system volume](https://support.apple.com/en-us/HT210650)), mount the system drive read/write (yes, this is in addition to disabling SIP)
    1. Download this ruby script in that directory:

    ```
    sudo mount -uw /
    ```
    1. Connect *only* the problem monitor
    1. Download this script in the directory containing all the display override plist files (note: even with the steps above, this command requires sudo to run):
    ```
    cd /System/Library/Displays/Contents/Resources/Overrides
    ```shell
    cd /Library/Displays/Contents/Resources/Overrides
    sudo curl -O https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    ```

    You may also want to use [adaugherity's version](https://gist.github.com/adaugherity/7435890) of the script:
    *Note: You may want to use [adaugherity's version](https://gist.github.com/adaugherity/7435890) of the script instead.*
    ```
    cd /System/Library/Displays/Contents/Resources/Overrides
    sudo curl -O https://gist.github.com/adaugherity/7435890/raw/patch-edid.rb
    ```
    1. Run the script we just downloaded (as root again). This creates a new display override plist.
    1. Run the script we just downloaded (as root again). This creates a new display override plist file.
    ```
    ```shell
    cd /Library/Displays/Contents/Resources/Overrides
    sudo ruby patch-edid.rb
    ```
    1. Reboot into recovery mode to re-enable SIP.
    1. Unplug and replug in the problem display.
    ```
    csrutil enable
    ```
    ### Additional reading/acknowledgements
    * [The original forum thread](http://embdev.net/topic/284710)
    * An improved version of the script [by adaugherity](https://gist.github.com/adaugherity/7435890)
    * [An explaination of the problem](https://spin.atomicobject.com/2018/08/24/macbook-pro-external-monitor-display-problem/) from Atomic Object's blog
    * Thanks so much to @stackrainbow for [pointing out](https://gist.github.com/ejdyksen/8302862#gistcomment-3460110) that this can be done without disabling SIP.
    * This version appears to work in Catalina and Big Sur. See earlier revisions for what worked (with disabling SIP) in earlier versions of macOS, which require the override plist to be in a different directory.
  2. @ejdyksen ejdyksen renamed this gist Jun 18, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @ejdyksen ejdyksen revised this gist Jun 18, 2020. 1 changed file with 15 additions and 2 deletions.
    17 changes: 15 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,14 @@

    A script to fix EDID problems on external monitors in Mac OS.

    ### Additional reading

    * [The original forum thread](http://embdev.net/topic/284710)
    * An improved version of the script [by adaugherity](https://gist.github.com/adaugherity/7435890)
    * [An explaination of the problem](https://spin.atomicobject.com/2018/08/24/macbook-pro-external-monitor-display-problem/) from Atomic Object's blog

    ### Instructions

    ⚠️ **This requires disabling SIP, so run this at your own risk. Be sure to re-enable SIP at the end.**

    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) while in [Recovery Mode](https://support.apple.com/en-us/HT201314). Reboot back into macOS when done.
    @@ -25,6 +33,13 @@ A script to fix EDID problems on external monitors in Mac OS.
    sudo curl -O https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    ```
    You may also want to use [adaugherity's version](https://gist.github.com/adaugherity/7435890) of the script:
    ```
    cd /System/Library/Displays/Contents/Resources/Overrides
    sudo curl -O https://gist.github.com/adaugherity/7435890/raw/patch-edid.rb
    ```
    1. Run the script we just downloaded (as root again). This creates a new display override plist.
    ```
    @@ -36,5 +51,3 @@ A script to fix EDID problems on external monitors in Mac OS.
    ```
    csrutil enable
    ```
    Source: http://embdev.net/topic/284710
  4. @ejdyksen ejdyksen revised this gist Jun 18, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ A script to fix EDID problems on external monitors in Mac OS.

    ⚠️ **This requires disabling SIP, so run this at your own risk. Be sure to re-enable SIP at the end.**

    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) in [Recovery Mode](https://support.apple.com/en-us/HT201314).
    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) while in [Recovery Mode](https://support.apple.com/en-us/HT201314). Reboot back into macOS when done.

    ```
    csrutil disable
    @@ -31,7 +31,7 @@ A script to fix EDID problems on external monitors in Mac OS.
    sudo ruby patch-edid.rb
    ```
    1. Reboot into recovery mode and re-enable SIP.
    1. Reboot into recovery mode to re-enable SIP.
    ```
    csrutil enable
  5. @ejdyksen ejdyksen renamed this gist Jun 18, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @ejdyksen ejdyksen revised this gist Jun 18, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    A script to fix EDID problems on external monitors in Mac OS.

    🚨 **Note: As this requires disabling System Integrity Protection, run this at your own risk, and be sure to re-enable SIP at the end.** 🚨
    ⚠️ **This requires disabling SIP, so run this at your own risk. Be sure to re-enable SIP at the end.**

    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) in [Recovery Mode](https://support.apple.com/en-us/HT201314).

  7. @ejdyksen ejdyksen revised this gist Jun 18, 2020. 1 changed file with 27 additions and 10 deletions.
    37 changes: 27 additions & 10 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -2,22 +2,39 @@

    A script to fix EDID problems on external monitors in Mac OS.

    🚨 **Note: As this requires disabling System Integrity Protection, run this at your own risk, and be sure to re-enable SIP at the end.** 🚨

    1. Connect the problem monitor.
    1. Disable [System Integrity Protection](https://support.apple.com/en-us/HT204899) in [Recovery Mode](https://support.apple.com/en-us/HT201314).

    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).
    ```
    csrutil disable
    ```
    ```
    cd /System/Library/Displays/Overrides
    sudo curl -O https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    ```
    1. For macOS Catalina and newer (which uses a [read-only system volume](https://support.apple.com/en-us/HT210650)), mount the system drive read/write (yes, this is in addition to disabling SIP)
    ```
    sudo mount -uw /
    ```
    1. Connect *only* the problem monitor
    1. Download this script in the directory containing all the display override plist files (note: even with the steps above, this command requires sudo to run):
    ```
    cd /System/Library/Displays/Contents/Resources/Overrides
    sudo curl -O https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    ```
    1. Run the script we just downloaded (as root again). This creates a new display override plist.
    ```
    sudo ruby patch-edid.rb
    ```
    ```
    sudo ruby patch-edid.rb
    ```
    1. Reboot into recovery mode and re-enable SIP.
    1. Disconnect and reconnect the monitor.
    ```
    csrutil enable
    ```
    Source: http://embdev.net/topic/284710
  8. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,6 @@

    A script to fix EDID problems on external monitors in Mac OS.

    Source:
    http://embdev.net/topic/284710

    1. Connect the problem monitor.

    @@ -20,4 +18,6 @@ http://embdev.net/topic/284710
    sudo ruby patch-edid.rb
    ```

    1. Disconnect and reconnect the monitor.
    1. Disconnect and reconnect the monitor.

    Source: http://embdev.net/topic/284710
  9. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## patch-edid
    ## patch-edid.rb

    A script to fix EDID problems on external monitors in Mac OS.

  10. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ A script to fix EDID problems on external monitors in Mac OS.
    Source:
    http://embdev.net/topic/284710

    1. Connect the problem monitor
    1. Connect the problem monitor.

    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    @@ -20,4 +20,4 @@ http://embdev.net/topic/284710
    sudo ruby patch-edid.rb
    ```

    1. Disconnect and reconnect the monitor
    1. Disconnect and reconnect the monitor.
  11. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    ## patch-edid

    A script to fix EDID problems on external monitors in Mac OS.

    Source:
    http://embdev.net/topic/284710

    1. Connect the problem monitor

    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).
  12. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,16 @@
    1. Connect the problem monitor

    2. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).
    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo curl -O https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    ```

    1. Run the script we just downloaded (as root again). This creates a new display override plist.

    ```
    sudo ruby patch-edid.rb
    ```

    3. Disconnect and reconnect the monitor
    1. Disconnect and reconnect the monitor
  13. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,10 @@

    2. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```

    3. Disconnect and reconnect the monitor
  14. @ejdyksen ejdyksen renamed this gist Jan 7, 2014. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions README.md → patch-edid.md
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,8 @@

    2. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb

    3. Disconnect and reconnect the monitor
  15. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    1. Connect the problem monitor

    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).
    2. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```

    1. Disconnect and reconnect the monitor
    3. Disconnect and reconnect the monitor
  16. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    1) Connect the problem monitor
    1. Connect the problem monitor

    1) Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).
    1. Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```

    1) Disconnect and reconnect the monitor
    1. Disconnect and reconnect the monitor
  17. @ejdyksen ejdyksen revised this gist Jan 7, 2014. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    1) Connect the problem monitor

    1) Download this script into your `/System/Library/Displays/Overrides` (note: this file is only writeable by root, so some commands require `sudo`).

    ```
    cd /System/Library/Displays/Overrides
    sudo wget https://gist.github.com/ejdyksen/8302862/raw/patch-edid.rb
    sudo ruby patch-edid.rb
    ```

    1) Disconnect and reconnect the monitor
  18. @ejdyksen ejdyksen created this gist Jan 7, 2014.
    49 changes: 49 additions & 0 deletions patch-edid.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/usr/bin/ruby
    # Create display override file to force Mac OS X to use RGB mode for Display
    # see http://embdev.net/topic/284710
    #
    # Update 2013-06-24: added -w0 option to prevent truncated lines

    require 'base64'

    data=`ioreg -l -w0 -d0 -r -c AppleDisplay`

    edid_hex=data.match(/IODisplayEDID.*?<([a-z0-9]+)>/i)[1]
    vendorid=data.match(/DisplayVendorID.*?([0-9]+)/i)[1].to_i
    productid=data.match(/DisplayProductID.*?([0-9]+)/i)[1].to_i

    puts "found display: vendorid #{vendorid}, productid #{productid}, EDID:\n#{edid_hex}"

    bytes=edid_hex.scan(/../).map{|x|Integer("0x#{x}")}.flatten

    puts "Setting color support to RGB 4:4:4 only"
    bytes[24] &= ~(0b11000)

    puts "Number of extension blocks: #{bytes[126]}"
    puts "removing extension block"
    bytes = bytes[0..127]
    bytes[126] = 0

    bytes[127] = (0x100-(bytes[0..126].reduce(:+) % 256)) % 256
    puts
    puts "Recalculated checksum: 0x%x" % bytes[127]
    puts "new EDID:\n#{bytes.map{|b|"%02X"%b}.join}"

    Dir.mkdir("DisplayVendorID-%x" % vendorid) rescue nil
    f = File.open("DisplayVendorID-%x/DisplayProductID-%x" % [vendorid, productid], 'w')
    f.write '<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">'
    f.write "
    <dict>
    <key>DisplayProductName</key>
    <string>Display with forced RGB mode (EDID override)</string>
    <key>IODisplayEDID</key>
    <data>#{Base64.encode64(bytes.pack('C*'))}</data>
    <key>DisplayVendorID</key>
    <integer>#{vendorid}</integer>
    <key>DisplayProductID</key>
    <integer>#{productid}</integer>
    </dict>
    </plist>"
    f.close