01-30-2024 02:59 PM - edited 01-31-2024 10:16 AM
I've spent some time researching where these options are actually stored, and found them in all locked away in
#!/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
Posted on 01-31-2024 03:26 AM
Hi there, does this work on ipads?
Thanks
Posted on 01-31-2024 07:07 AM
Unfortunately, this is for MacOS only. Scripting is not an option for iOS devices.
Posted on 02-12-2024 07:53 AM
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.
Posted on 02-27-2024 02:11 PM
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.
Posted on 02-27-2024 02:45 PM
"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.
Posted on 05-28-2024 11:01 AM
I get an error "Set: Entry, ":CBUser-C02B2E82-A6D5-463F-8001-EAC91E5D406C:CBColorAdaptationEnabled", Does Not Exist" when trying to set the True Tone (only). Any ideas?
Posted on 05-28-2024 11:44 AM
I'm honestly not sure. Because the "primary" display seems to receive a random ID, I can't be sure. It took a lot of work to source out all of the files and IDs, and honestly it still never worked quite right.
Posted on 05-28-2024 12:28 PM
Thanks, I THINK I figured it out. I've never used PlistBuddy so it took me a while to decipher what you wrote. It seems the CBColorAdatationEnable key doesn't exist in the plist until it's changed so modified through the GUI:
[[ ! -z "$trueTone" ]] && {
$plistPal -c "Add :CBUser-$userID:CBColorAdaptationEnabled integer $trueTone" "$configRoot" 2>/dev/null;
$plistPal -c "Set :CBUser-$userID:CBColorAdaptationEnabled $trueTone" "$configRoot"; }
A reboot is required to get the setting to take... I'm sure there's a process that can be killed instead of a reboot but to be honest I'm not that bright to figure these things out.
Posted on 05-28-2024 12:49 PM
Ah yes. You definitely have to use ADD or SET depending on whether the value exists first or not.I will frequently wipe out an entire plist and then I can use ADD for everything, but that didn't work in this scenario.
As for killing processes, I killed a *lot* of processes trying to aim for the correct one and never found it, so I had to use the reboot to get it to take.
Posted on 05-28-2024 03:09 PM
Did some more digging:
1. A log out will do
2. sudo killall corebrightnessd and sudo killall WindowServer
Posted on 05-28-2024 12:59 PM
[[ ! -z "$trueTone" ]] && {
if ! $plistPal -c "Print :CBUser-$userID:CBColorAdaptationEnabled" "$configRoot" 2>/dev/null; then
$plistPal -c "Add :CBUser-$userID:CBColorAdaptationEnabled integer 0" "$configRoot";
else
$plistPal -c "Set :CBUser-$userID:CBColorAdaptationEnabled $trueTone" "$configRoot";
fi
}
Posted on 07-30-2024 05:47 PM
@kacey3 What do you set the empty variables to at the beginning of your script
# Set empty variables
trueTone=""
autoBright=""
brightLevel=""
Posted on 07-31-2024 07:00 AM
These are intentionally empty and are not intended to be filled. These same variables will be set by parameters, but if a certain parameter is not set, we still need an empty variable later in the script.
Posted on 07-31-2024 01:17 PM
Thanj you. Everytime I run it manually for testing I get the following results and nothign changes
True Tone option will not be changed.
Auto Brightness option will not be changed.
Brightness Level will not be changed.
Posted on 07-31-2024 01:30 PM
Are you setting the parameters in the script in the policy?
Posted on 07-31-2024 01:39 PM
duh!!! thanks. that was it. however the when running the script, the settings change for a split second then revert, even when killing the corebrightnessd and Windowserver processors. Any thoughts on that?
Posted on 07-31-2024 01:48 PM
I found that it only ever worked after a full restart... and even then, it was inconsistent at best. I mostly used it for setting the options once, but then they never really stuck if someone changed them manually later.
Sorry I couldn't be of more help. This is one of those projects that I put a lot of effort into, and then was kind of defeated by Apple in general.
Posted on 07-31-2024 03:48 PM
Understood. thank you. by chance did you see the screenshot I posted with the error message?
Posted on 07-31-2024 04:25 PM
This was my final script based on @kacey3 's work which is working for me. I only use it to turn off TrueTone:
Posted on 07-31-2024 06:50 PM
Thank you. unforntuately I cannot get it to work. it disables true tone, the screen color changes, but then in a couple seconds reverts back.
Posted on 08-01-2024 08:21 AM
And you're using the script parameters?
And you're using the script parameter?
Posted on 08-01-2024 08:54 AM
Yep..same as the screenshot above that @kacey3 posted.
Truetone gets disabled and the screen color changes, then after about 3-4 seconds it slowly reverts back to the "yellow" true tone color.
Posted on 08-01-2024 11:53 AM
Maybe you have another policy (from your testing) or config profile that's changing things back?
Posted on 08-02-2024 05:43 AM
unfortunately no. this mac is running in our jamf sandbox testing server that literally has nothing on it.
Posted on 08-02-2024 05:50 AM
Try wiping the test computer and starting over? I deployed the setting this way to over 300 computers and its working for us.
Posted on 07-31-2024 01:42 PM
This is the script result