-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhidpi_osx.rb
57 lines (42 loc) · 1.51 KB
/
hidpi_osx.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'base64'
require 'fileutils'
ioreg = `ioreg -l`.scrub.lines
displays = ioreg.grep(/DisplayVendorID/)
system_dir = "/System/Library/Displays/Overrides"
displays.size.times do |i|
vendor_id = ioreg.grep(/DisplayVendorID/)[i].match(/= (.*)/)[1]
# skip apple displays
next if vendor_id == "1552"
product_id = ioreg.grep(/DisplayProductID/)[i].match(/= (.*)/)[1]
edid = ioreg.grep(/IODisplayEDID/)[i].match(/<(.*)>/)[1]
resolutions = [[1280, 800]]
vendor_dir = File.join(system_dir, "DisplayVendorID-#{vendor_id}")
plist_path = File.join(vendor_dir, "DisplayProductID-#{product_id}")
plist = %Q[
<?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">
<dict>
<key>DisplayProductID</key>
<integer>#{product_id}</integer>
<key>DisplayVendorID</key>
<integer>#{vendor_id}</integer>
<key>IODisplayEDID</key>
<data>
#{Base64.encode64([edid].pack('H*'))}</data>
<key>scale-resolutions</key>
<array>
#{resolutions.map{|w, h| "<data>#{Base64.encode64([w, h, 1].pack('N*')).strip}</data>" }.join("\n")}
</array>
</dict>
</plist>].strip
puts plist
begin
FileUtils.mkdir_p(vendor_dir)
File.open(plist_path, "w") do |f|
f.puts plist
end
rescue Errno::EACCES
warn "Please run this command with sudo, and turn off File System Protection in El Capitain"
end
end