Skip to content

Instantly share code, notes, and snippets.

@jeremy4971
Last active January 6, 2024 10:30
Show Gist options
  • Save jeremy4971/032e1581a53aa9127f42969e9f817ce5 to your computer and use it in GitHub Desktop.
Save jeremy4971/032e1581a53aa9127f42969e9f817ce5 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"
# 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 "Preferences…" of menu 1 of menu bar item "Finder" of menu bar 1
repeat until exists window "Finder Preferences"
end repeat
click button "Sidebar" of tool bar 1 of window "Finder Preferences"
if not (value of checkbox 7 of scroll area 1 of window "Finder Preferences" as boolean) then
click checkbox 7 of scroll area 1 of window "Finder Preferences"
end if
if not (value of checkbox 8 of scroll area 1 of window "Finder Preferences" as boolean) then
click checkbox 8 of scroll area 1 of window "Finder Preferences"
end if
if not (value of checkbox 9 of scroll area 1 of window "Finder Preferences" as boolean) then
click checkbox 9 of scroll area 1 of window "Finder Preferences"
end if
if not (value of checkbox 10 of scroll area 1 of window "Finder Preferences" as boolean) then
click checkbox 10 of scroll area 1 of window "Finder Preferences"
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 "Settings…" of menu 1 of menu bar item "Finder" of menu bar 1
repeat until exists window "Finder Settings"
end repeat
click button "Sidebar" of toolbar 1 of window "Finder Settings"
if not (value of checkbox 7 of scroll area 1 of window "Finder Settings" as boolean) then
click checkbox 7 of scroll area 1 of window "Finder Settings"
end if
if not (value of checkbox 8 of scroll area 1 of window "Finder Settings" as boolean) then
click checkbox 8 of scroll area 1 of window "Finder Settings"
end if
if not (value of checkbox 9 of scroll area 1 of window "Finder Settings" as boolean) then
click checkbox 9 of scroll area 1 of window "Finder Settings"
end if
if not (value of checkbox 10 of scroll area 1 of window "Finder Settings" as boolean) then
click checkbox 10 of scroll area 1 of window "Finder Settings"
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