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.