Accessing PRAM parameters on Macintosh

Hi all,

Other than System Preferences, is there a way to access PRAM parameters or registers on Macintosh, using declares, plugins or anything else ?
I’d like to programatically modifiy Monitor brightness.
I looked at Google, Xojo language reference, MBS plugins, but found nothing.

Thanks for any advise or idea.

You use nvram command line tool.

You are off-track - those values might be stored in PRAM but you should not attempt to control them directly.

I suggest you start here, which may take some translation into Xojo:


Thanks, Christian.

Great! Many thanks, Eric.
I’m quite sure this will do the trick.

Could someone help me coding this in Xojo ?

extern int DisplayServicesGetBrightness(int display, float *brightness);
extern int DisplayServicesSetBrightness(int display, float brightness);
/* Change brightness */
float brightness = 0.8;
int err = DisplayServicesSetBrightness(1, brightness);
/* Get current brightness */
err = DisplayServicesGetBrightness(1, &brightness);

I tried the code below and some variations, but I always got the “FunctionNotFoundException” error.

Soft Declare Sub DisplayServicesGetBrightness  Lib "DisplayServices" (display As Integer, brightness As Ptr)

Dim Err As Integer
Dim brightness As MemoryBlock

DisplayServicesGetBrightness(1, brightness)

In addition, where could I find DisplayServices APIs listing? Is there somewhere something for Apple like MSDN for Windows? None of my searches on Internet was successful…

Thanks a lot.

iMac 2020, Xojo 2021r3.1, MacOS Monterey 12.2.1

Try those parameters: (display As Int32, byref brightness As single)
to correct them.

This returns links, but I do not know how useful they can be: DisplayServices

Salut doc…

Found the solution by myself, with the help of this web page:

Here is what I coded:

Soft Declare Function CoreDisplay_Display_GetUserBrightness Lib "CoreDisplay" (display As Integer) As Double

Soft Declare Sub CoreDisplay_Display_SetUserBrightness Lib "CoreDisplay" (display As Integer, brightness As Double)

Dim Err As Integer
Dim brightness As MemoryBlock

TextArea1.AddText "Get Brightness : " +CoreDisplay_Display_GetUserBrightness(0).ToString+EndOfLine

TextArea1.AddText "Set Brightness to "+TextField1.Text+EndOfLine

CoreDisplay works well. It seems like DisplayServicesGetBrightness works on M1.
Nevertheless, I will try suggestions from Christian and give you a feedback.

If someone has a solution for DisplayServicesGetBrightness on Intel Macs, thanks to share it.

Many thanks to all replyers.

Thanks Christian.
Sorry, it does not work. Always FunctionNotFoundException error.

DisplayServicesGetBrightness is declared in a private Framework.
You may try

Soft Declare Sub DisplayServicesGetBrightness  Lib "/System/Library/PrivateFrameworks/DisplayServices.framework" (display As Integer, byref brightness As Single)
Soft Declare Sub DisplayServicesSetBrightness  Lib "/System/Library/PrivateFrameworks/DisplayServices.framework" (display As Integer, brightness As Single)

Not tested.

Thanks for your help, Tom.
Yes, indeed, no more “FunctionNotFoundException” error. Unfortunately, these calls do not work on Intel Macs, it seems like they are intended for use on M1.


Soft Declare Function DisplayServicesGetBrightness  Lib "/System/Library/PrivateFrameworks/DisplayServices.framework" (display As Integer, brightness As Double) As Int64
Soft Declare Function DisplayServicesSetBrightness  Lib "/System/Library/PrivateFrameworks/DisplayServices.framework" (display As Int64, brightness As Double) As Int64

Dim Err As Int64
Dim brightness As Double

Err=DisplayServicesGetBrightness(0, brightness)

TextArea1.AddText "Get Brightness : " +Brightness.ToString+", erreur n° "+Err.ToString+EndOfLine

TextArea1.AddText "Set Brightness to 0.8, erreur n° "+Err.ToString+EndOfLine

I get neither exception error, nor correct result. I’m just getting err=1000 when getting the brightness, err=0 but no change in brightness when setting it.

Tried with brightness as Simple, as MemoryBlock (that is Ptr in the Get declare), with display=0 or 1.

On Intel Macs, CoreDisplay_Display_GetUserBrightness and CoreDisplay_Display_SetUserBrightness work perfectly.

Could someone owning a M1 Mac test DisplayServices code? Thanks to her/him.