kfix / ddcctl

DDC monitor controls (brightness) for Mac OSX command line
GNU General Public License v3.0
1.85k stars 151 forks source link

macOS Monterey: Failed to parse WindowServer's preferences! (/Library/Preferences/com.apple.windowserver.plist) #122

Open adams-family opened 2 years ago

adams-family commented 2 years ago

I've been using ddcctl on my Display with MacBook Pro 2018 (Intel) - worked perfectly, I'm addicted to it.

Now I've replaced my laptop with a MacBook Pro 2021 (M1), installed ddctl via homebrew but unfortunately it does not work anymore - same display, same cable, just different laptop.

$ ddcctl -d 1 -c 1
D: CGDisplay C1BE29A5-BFC9-4EDA-82B0-1E638BB772F7 dispID(#3) (1920x1080 0°) HiDPI
D: CGDisplay A6A4A5E4-6D41-4340-843E-FD4361382A24 dispID(#2) (1440x900 0°) 89.00 DPI
I: found 2 external displays
E: Failed to parse WindowServer's preferences! (/Library/Preferences/com.apple.windowserver.plist)
E: Failed to acquire framebuffer device for display

I can confirm that such a file does not exist:

cat /Library/Preferences/com.apple.windowserver.plist
cat: /Library/Preferences/com.apple.windowserver.plist: No such file or directory

I searched my entire drive with "find" and I haven't found a file with such a name at all. I'm happy to help with testing if you had an idea on how to fix it.

adams-family commented 2 years ago

Ok, I think this might be the file we are looking for?

/Library/Preferences/com.apple.windowserver.displays.plist
adams-family commented 2 years ago

All right, I confirm that even if I change the file path to the above, the app is still failing with:

2022-02-14 16:08:21.539 ddcctl[6486:275857] D: CGDisplay C1BE29A5-BFC9-4EDA-82B0-1E638BB772F7 dispID(#2) (1920x1080 0°) HiDPI
2022-02-14 16:08:21.539 ddcctl[6486:275857] -[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x96e7084facc55e4e
2022-02-14 16:08:21.539 ddcctl[6486:275857] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x96e7084facc55e4e'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001a8f2c1cc __exceptionPreprocess + 240
    1   libobjc.A.dylib                     0x00000001a8c7d7b8 objc_exception_throw + 60
    2   CoreFoundation                      0x00000001a8fbf1a0 -[NSObject(NSObject) __retain_OA] + 0
    3   CoreFoundation                      0x00000001a8e8c360 ___forwarding___ + 1728
    4   CoreFoundation                      0x00000001a8e8bbe0 _CF_forwarding_prep_0 + 96
    5   ddcctl                              0x0000000100c8b6bc getDisplayDeviceLocation + 428
    6   ddcctl                              0x0000000100c8c074 main + 852
    7   dyld                                0x0000000100d9d0f4 start + 520
)
libc++abi: terminating with uncaught exception of type NSException
Abort trap: 6

Which has been reported here: https://github.com/kfix/ddcctl/issues/86

And I also found that my issue has already been reported here: https://github.com/kfix/ddcctl/issues/114

Sorry for the duplicates. I'd love to help solving this, problem is my C programming skills are very limited.

kfix commented 2 years ago

I'll look into removing or fixing that code but M1s are not supported yet so this is the least of your issues.

adams-family commented 2 years ago

I made some debugging and I discovered the following:

However, I have a good news for you and for myself, as well: there is a tool called m1ddc which is very short, very straightforward and working fine on M1 and Monterey (I'm using it right now), so that could serve you as a reference. Hope it helps!

vizcay commented 2 years ago

However, I have a good news for you and for myself, as well: there is a tool called m1ddc which is very short, very straightforward and working fine on M1 and Monterey (I'm using it right now), so that could serve you as a reference. Hope it helps!

Unfortunately no luck for us using HDMI displays:

Please note that controlling a HDMI display via the 2020 M1 Mini's HDMI port is not working. You have to use DisplayPort over USB-C!

azubala commented 2 years ago

@adams-family thanks for sharing the m1ddc tool!

luco commented 1 year ago

Getting this as well on i5 Mac Mini

Takdrift commented 1 year ago

I made some debugging and I discovered the following:

  • the format of the two Preferences files (Monterey and Big Sur) are different, that's where the code fails as it's expecting a key in the dictionary that does not exist
  • even if I remove the code that's trying to parse the Preferences file, the IOServiceGetMatchingServices function is returning an empty iterator, so I'm not able to get through

However, I have a good news for you and for myself, as well: there is a tool called m1ddc which is very short, very straightforward and working fine on M1 and Monterey (I'm using it right now), so that could serve you as a reference. Hope it helps!

m1ddc is perfect for M1 MacBook Pro, and you can change the input of display by just using a shortcut by automator, cheers!

sunknudsen commented 3 months ago

Thanks for sharing @Takdrift, m1ddc works like a charm.