SOLVED: Set True Tone, Auto Brightness, and Brightness Level (Display Settings)

kacey3
Contributor II

I've spent some time researching where these options are actually stored, and found them in all locked away in 

/private/var/root/Library/Preferences/com.apple.CoreBrightness.plist
 
This file is editable by all users, as it simply stores the current display tone and brightness settings. The only trick is, this file is only read at startup, so editing it does require a restart afterwards. For our computers labs and classrooms, we simply run this script at every login. That does mean, however, that if someone changes the display settings, it takes two restarts to get them to go back to our desired default settings (if someone can figure out what service or process to restart to force the preferences to update, that would be great, but for now, this solution is working for us).
 
Update: I have discovered that in order for this to work, you also need to have opened and closed System Settings. I will be working on finding a way around that. For the time being, we have simply added commands to launch System Settings and then restart the computer to our policy, and we only run the policy after hours so that our lab and classroom computers start every day with the correct display settings.

For those who are interested in our solution, here is the script that I wrote up:
#!/bin/bash

##########################################################################################################################################################
#
# Set Display Settings
# Written by KClose
# Created:  January 30, 2024
#
# Sets the default Brightness level, Auto Brightness option, and True Tone option. 
#   The plist is only read upon startup, so changing these settings via this script will not take effect until the first restart after the script is run.
#
##########################################################################################################################################################

### FETCH VARIABLES ###

# Set empty variables
trueTone=""
autoBright=""
brightLevel=""

# Fetch True Tone option.
if [[ $4 == [Nn] ]]; then
    echo "True Tone will be disabled."
    trueTone="0"
elif [[ $4 == [Yy] ]]; then
	echo "True Tone will be enabled."
    trueTone="1"
else
    echo "True Tone option will not be changed."
fi

# Fetch Auto Brightness option.
if [[ $5 == [Nn] ]]; then
    echo "Auto Brightness will be disabled."
    autoBright="false"
elif [[ $5 == [Yy] ]]; then
    echo "Auto Brightness will be enabled."
    autoBright="true"
else
    echo "Auto Brightness option will not be changed."
fi

# Fetch Brightness Level
#   The recomended value at the time this script was written is a real number between 3 and 525.
#   This value was derived from an M1 iMac. 
[[ -z "$6"  ]] && { echo "Brightness Level will not be changed."; } || { brightLevel="$6"; echo "Brightness Level will be set to $brightLevel"; }

# Fetch Current User
currentUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')

# Fetch GUID of Current User
userID=$(dscl . -read /Users/$currentUser/ GeneratedUID | awk -F': ' '{print $2}')

# Shortcut the PlistBuddy command for convnience.
plistPal="/usr/libexec/PlistBuddy"

# Define the Configuration File locations.
configRoot="/private/var/root/Library/Preferences/com.apple.CoreBrightness.plist"

# Fetch ID of Primary Display
displayID=$($plistPal -c "Print :DisplayPreferences:" "$configRoot" | grep "= Dict" | grep -v AutoBrightnessCurve | awk '{print $1}')

### MAIN SCRIPT ###

# Set options in the root Plist
[[ ! -z "$trueTone" ]] && { $plistPal -c "Set :CBUser-$userID:CBColorAdaptationEnabled $trueTone" "$configRoot"; }
[[ ! -z "$autoBright" ]] && { $plistPal -c "Set :DisplayPreferences:$displayID:AutoBrightnessEnable $autoBright" "$configRoot"; }
[[ ! -z "$brightLevel" ]] && { $plistPal -c "Set :DisplayPreferences:$displayID:BrightnessLevelNits $brightLevel" "$configRoot"; }

exit 0
5 REPLIES 5

vickymckay
New Contributor

 Hi there, does this work on ipads?

Thanks

Unfortunately, this is for MacOS only. Scripting is not an option for iOS devices.

kacey3
Contributor II

Upon further testing, while this worked flawlessly on my test system, it seems like it is inconsistent at best in practice. I will continue to work on this at my leisure, but Apple is not making this an easy thing to enforce.

areimer
New Contributor II

This is useful. Thanks. I found the same plist because I needed Auto Brightness to be off due to our colour-calibrated computer labs. (True Tone as well, but almost no one is working here that late.) Because setting the brightness value has been the biggest improvement we are looking at (returning it to the value at calibration time), we are testing "brightness" (https://github.com/nriley/brightness) and Outset to reset the brightness at login time. It uses APIs, which means the change happens immediately upon run.

I'm presuming the reason `defaults write` isn't being used here is because we don't know the display ID.

"Defaults Write" could be used, I'm sure, but I am a fan of PlistBuddy, so I tend to start there unless there's something I can't do with it. You would still need to use a "Defaults Read" (or some similar method) to find the correct Display ID. Otherwise, in my experience, PlistBuddy and Defaults are fairly interchangable.