Last active
January 6, 2024 10:30
-
-
Save jeremy4971/805c09aaf2f0657c89f23b80809bc5ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# | |
# Created : 2022-09-09 | |
# Last Modified : 2022-10-19 | |
# 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" | |
# Exit if OS language is not in French | |
OS_LANG=$(defaults read /Library/Preferences/.GlobalPreferences.plist "AppleLanguages" | tr -d '\n' | awk -F'"' '{print $2}') | |
echo "$OS_LANG" | |
if ! [[ "$OS_LANG" = "fr-FR" || "$OS_LANG" = "en-FR" ]]; then | |
echo "OS language is NOT in French. Exiting" | |
exit 0 | |
else | |
echo "Pas mal non, c’est français." | |
fi | |
# 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 "Préférences Système" | |
repeat until exists group 1 of window "Moniteurs" | |
end repeat | |
if (value of checkbox "Régler la luminosité automatiquement" of group 1 of window "Moniteurs" as boolean) then | |
click checkbox "Régler la luminosité automatiquement" of group 1 of window "Moniteurs" | |
end if | |
if (value of checkbox "True Tone, L’écran s’adapte automatiquement pour optimiser l’affichage des couleurs selon les différentes conditions d’éclairage ambiant." of group 1 of window "Moniteurs" as boolean) then | |
click checkbox "True Tone, L’écran s’adapte automatiquement pour optimiser l’affichage des couleurs selon les différentes conditions d’éclairage ambiant." of group 1 of window "Moniteurs" | |
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 "Réglages Système" | |
repeat until exists group 1 of window "Moniteurs" | |
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 "Moniteurs" 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 "Moniteurs" | |
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 "Moniteurs" 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 "Moniteurs" | |
end if | |
end tell | |
delay 1.0 | |
quit application "System Preferences" | |
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