Skip to content

Instantly share code, notes, and snippets.

@mfaughn
Created April 13, 2022 22:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfaughn/57d95a8c06620a88fd2e651167a2c2ed to your computer and use it in GitHub Desktop.
Save mfaughn/57d95a8c06620a88fd2e651167a2c2ed to your computer and use it in GitHub Desktop.
M1 Mac futzing about with EDID and name of display
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use a different name for the display
# This doesn't quite work since it just appends the alphanumeric serial number of whichever display of any given type to all of the names of the that type of display.
require 'base64'
edit_bytes = false
data=`ioreg -l -w0 -d0 -r -c AppleCLCD2`
# edid_hex=data.match(/EDID UUID.*?<([a-z0-9]+)>/i)
edid_hexes = data.scan /(?<="EDID UUID" = ).+/
# pp edid_hex; puts
display_attributes = data.scan /(?<="DisplayAttributes" = ).+/
# pp display_attributes; puts
edid_hexes.each_with_index do |edid, i|
puts "EDID UUID #{edid}"
dai = display_attributes[i].gsub('=', ' => ')
# puts dai;puts '*************'
dai = dai.gsub(/=> ([^"({].*?)(?=[,}])/, '=> "' + '\1' + '"').gsub(/","/, '", "')
# puts dai
display_attributes_hash = eval(dai)
product_attributes = display_attributes_hash["ProductAttributes"]
pp product_attributes
vendorid = product_attributes["LegacyManufacturerID"]
vendorid_hex = vendorid.to_i.to_s(16)
# puts vendorid_hex
productid = product_attributes["ProductID"]
productid_hex = productid.to_i.to_s(16)
# puts productid_hex
alphanumeric = product_attributes["AlphanumericSerialNumber"]
prod_name = product_attributes["ProductName"]
new_name = "#{prod_name} (#{alphanumeric})"
puts '-----------------'
# I haven't messed with anything in here....
if edit_bytes
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}"
end
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>#{new_name}</string>
<key>DisplayVendorID</key>
<integer>#{vendorid}</integer>
<key>DisplayProductID</key>
<integer>#{productid}</integer>
</dict>
</plist>"
f.close
end
@glyph
Copy link

glyph commented Jan 19, 2023

Attempting to run this script on an M1 Max Macbook Pro with an LG monitor plugged into DisplayPort on a CalDigit dock gives me this:

EDID UUID "1E6D4D77-0000-0000-071F-0104B5582578"
{}
-----------------
edid_rename_display.rb:50:in `%': can't convert nil into Integer (TypeError)
	from edid_rename_display.rb:50:in `block in <main>'
	from edid_rename_display.rb:13:in `each'
	from edid_rename_display.rb:13:in `each_with_index'
	from edid_rename_display.rb:13:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment