Skip to content

Instantly share code, notes, and snippets.

@jeremy4971
Last active January 6, 2024 10:30
Show Gist options
  • Save jeremy4971/ac3adbe4802aed9ba14e99dd076daa71 to your computer and use it in GitHub Desktop.
Save jeremy4971/ac3adbe4802aed9ba14e99dd076daa71 to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Created : 2022-09-09
# Last Modified : 2022-10-24
# Version : 2.0
# Tested with : macOS 12.6 / macOS 13.0
#
###
# Read logged in user
loggedInUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')
echo "Hello, I am $loggedInUser"
# Read macOS version
macos=$(sw_vers -productVersion)
#############
# FUNCTIONS #
#############
# Disable True Tone & Auto Brightness
# Doesn't work if you have an external monitor plugged in
truetone_monterey() {
open "/System/Applications/System Preferences.app"
sleep 3
open "/System/Library/PreferencePanes/Displays.prefPane"
sleep 1
sudo -u "$loggedInUser" osascript -e '
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
repeat until exists group 1 of window "Displays"
end repeat
if (value of checkbox "Automatically adjust brightness" of group 1 of window "Displays" as boolean) then
click checkbox "Automatically adjust brightness" of group 1 of window "Displays"
end if
if (value of checkbox "True Tone, Automatically adapt display to make colours appear consistent in different ambient lighting conditions." of group 1 of window "Displays" as boolean) then
click checkbox "True Tone, Automatically adapt display to make colours appear consistent in different ambient lighting conditions." of group 1 of window "Displays"
end if
end tell
delay 1.0
quit application "System Preferences"
end tell
'
}
truetone_ventura() {
open "/System/Applications/System Settings.app"
sleep 3
open "/System/Library/PreferencePanes/Displays.prefPane"
sleep 1
sudo -u "$loggedInUser" osascript -e '
activate application "System Settings"
tell application "System Events"
tell process "System Settings"
repeat until exists group 1 of window "Displays"
end repeat
if (value of checkbox 1 of group 2 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays" as boolean) then
click checkbox 1 of group 2 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays"
end if
if (value of checkbox 2 of group 2 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays" as boolean) then
click checkbox 2 of group 2 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays"
end if
end tell
delay 1.0
quit application "System Settings"
end tell
'
}
#################
# END FUNCTIONS #
#################
if [[ "$macos" == "12."* ]]; then
echo "MONTEREY"
truetone_monterey
elif [[ "$macos" == "13."* ]]; then
echo "VENTURA"
truetone_ventura
else
echo "UNKNOWN OS"
exit 0
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment