Skip to content

Instantly share code, notes, and snippets.

@tedserbinski
Created May 29, 2024 22:04
Show Gist options
  • Save tedserbinski/2179d4f8aea8a830d200c6052791cffb to your computer and use it in GitHub Desktop.
Save tedserbinski/2179d4f8aea8a830d200c6052791cffb to your computer and use it in GitHub Desktop.
Set which applications go in the dock on MacOS
# source: https://community.jumpcloud.com/t5/community-scripts/using-dockutil-to-set-a-user-s-dock/m-p/1897
#!/bin/bash
# check if dockutil is installed, install if it's not.
dockutil="/usr/local/bin/dockutil"
if [[ -x $dockutil ]]; then
echo "dockutil found, no need to install"
else
echo "dockutil could not be found, installing..."
curl -L --silent --output /tmp/dockutil.pkg "https://github.com/kcrawford/dockutil/releases/download/3.1.3/dockutil-3.1.3.pkg" >/dev/null
# install dockutil
installer -pkg "/tmp/dockutil.pkg" -target /
fi
# vars to use script and set current logged in user dock
killall="/usr/bin/killall"
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
LoggedInUserHome="/Users/$loggedInUser"
UserPlist=$LoggedInUserHome/Library/Preferences/com.apple.dock.plist
################################################################################
# Use Dockutil to Modify Logged-In User's Dock
################################################################################
echo "------------------------------------------------------------------------"
echo "Current logged-in user: $loggedInUser"
echo "------------------------------------------------------------------------"
echo "Removing all Items from the Logged-In User's Dock..."
sudo -u $loggedInUser $dockutil --remove all --no-restart $UserPlist
echo "Creating New Dock..."
sudo -u $loggedInUser $dockutil --add "/System/Applications/Launchpad.app" --no-restart --position 1 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Google Chrome.app" --no-restart --position 2 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Stickies.app" --no-restart --position 3 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Reminders.app" --no-restart --position 4 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Notes.app" --no-restart --position 5 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Freeform.app" --no-restart --position 6 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Photos.app" --no-restart --position 7 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Books.app" --no-restart --position 8 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/System Settings.app" --no-restart --position 9 --allhomes $UserPlist
sudo -u $loggedInUser $dockutil --add "~/Downloads" --section others --view auto --display folder --no-restart --allhomes $UserPlist
echo "Restarting Dock..."
sudo -u $loggedInUser $killall Dock
exit 0
@tedserbinski
Copy link
Author

I don't think the the flag --allhomes works in this script since it looks at the logged in user. Need to update script to work for all users if that is the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment