Skip to content

Instantly share code, notes, and snippets.

@glyph
Created January 19, 2023 09: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 glyph/86421ad155c4f9bf30932205e14974de to your computer and use it in GitHub Desktop.
Save glyph/86421ad155c4f9bf30932205e14974de to your computer and use it in GitHub Desktop.
#!/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 = true
data=`ioreg -l -w0 -d0 -r -c AppleCLCD2`
# edid_hex=data.match(/EDID UUID.*?<([a-z0-9]+)>/i)
# pp 'hex'; pp edid_hex;
edid_hexes = data.scan /(?<="EDID UUID" = ).+/
pp edid_hexes; 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+1].gsub('=', ' => ')
puts '*8* *8* *8*'
puts dai
puts '*************'
# next if dai == '{"ProductAttributes" => {}}'
puts 'keep goin'
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment