ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
563 stars 47 forks source link

DisplayServices exit with 139 code. #562

Closed Alexandro1112 closed 1 year ago

Alexandro1112 commented 1 year ago

Describe the bug

I found a great DisplayServices framework and loaded it into python via pyobjc, with loadBundle I load 1 function, for using in python. DisplayServicesGetBrightness to determine screen brightness, exited with code 139 after running python script.Look at this:


import objc

def load():

    objc._objc.loadBundleFunctions(objc.loadBundle('DisplayServices', bundle_path='/System/Library/PrivateFrameworks/DisplayServices.framework',  # noqa
                    module_globals=globals()), globals(), [('DisplayServicesGetBrightness', b'iI@')]) 
load()

CGDirectDisplayID = 1
print(globals()['DisplayServicesGetBrightness'](CGDirectDisplayID, None))

MacOs Ventura 13.1 64 arch.

To Reproduce Script should return value depending of screen brightness level.

Expected behavior Return value depending of brightness level of screen.

Additional context Earlier I use DisplayServicesGetBrightness for adjust brightness for determine display. Code successful adjust brightness.

ronaldoussoren commented 1 year ago

You're trying to call a private API, whether that works or not depends on the interface you somehow deduced. Crashes can occur when you get this wrong.

According to https://github.com/nriley/brightness/blob/master/brightness.c the function has a different interface, in particular the second argument is a pointer to float where the value is returned (o^f) and the return value is a status code.