Skip to content

Instantly share code, notes, and snippets.

@jeremy4971
Last active January 6, 2024 10:30
Show Gist options
  • Save jeremy4971/71a21ebdb2d02509e9878afcdd29465e to your computer and use it in GitHub Desktop.
Save jeremy4971/71a21ebdb2d02509e9878afcdd29465e to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Created : 2022-09-09
# Last Modified : 2022-10-25
# 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 #
#############
sidebar_monterey() {
sudo -u "$loggedInUser" osascript -e '
activate application "Finder"
tell application "System Events"
tell process "Finder"
delay 1.0
select menu bar 1
click menu bar item "Finder" of menu bar 1
delay 0.5
click menu 1 of menu bar item "Finder" of menu bar 1
click menu item "Préférences…" of menu 1 of menu bar item "Finder" of menu bar 1
repeat until exists window "Préférences du Finder"
end repeat
click button "Barre latérale" of tool bar 1 of window "Préférences du Finder"
if not (value of checkbox 7 of scroll area 1 of window "Préférences du Finder" as boolean) then
click checkbox 7 of scroll area 1 of window "Préférences du Finder"
end if
if not (value of checkbox 8 of scroll area 1 of window "Préférences du Finder" as boolean) then
click checkbox 8 of scroll area 1 of window "Préférences du Finder"
end if
if not (value of checkbox 9 of scroll area 1 of window "Préférences du Finder" as boolean) then
click checkbox 9 of scroll area 1 of window "Préférences du Finder"
end if
if not (value of checkbox 10 of scroll area 1 of window "Préférences du Finder" as boolean) then
click checkbox 10 of scroll area 1 of window "Préférences du Finder"
end if
end tell
delay 0.5
quit application "Finder"
end tell
'
}
sidebar_ventura() {
sudo -u "$loggedInUser" osascript -e '
activate application "Finder"
tell application "System Events"
tell process "Finder"
delay 1.0
select menu bar 1
click menu bar item "Finder" of menu bar 1
delay 0.5
click menu 1 of menu bar item "Finder" of menu bar 1
click menu item "Réglages…" of menu 1 of menu bar item "Finder" of menu bar 1
repeat until exists window "Réglages du Finder"
end repeat
click button "Barre latérale" of toolbar 1 of window "Réglages du Finder"
if not (value of checkbox 7 of scroll area 1 of window "Réglages du Finder" as boolean) then
click checkbox 7 of scroll area 1 of window "Réglages du Finder"
end if
if not (value of checkbox 8 of scroll area 1 of window "Réglages du Finder" as boolean) then
click checkbox 8 of scroll area 1 of window "Réglages du Finder"
end if
if not (value of checkbox 9 of scroll area 1 of window "Réglages du Finder" as boolean) then
click checkbox 9 of scroll area 1 of window "Réglages du Finder"
end if
if not (value of checkbox 10 of scroll area 1 of window "Réglages du Finder" as boolean) then
click checkbox 10 of scroll area 1 of window "Réglages du Finder"
end if
end tell
delay 0.5
quit application "Finder"
end tell
'
}
#################
# END FUNCTIONS #
#################
if [[ "$macos" == "12."* ]]; then
echo "MONTEREY"
sidebar_monterey
elif [[ "$macos" == "13."* ]]; then
echo "VENTURA"
sidebar_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