12-06-2022 03:52 PM - edited 12-06-2022 05:13 PM
It's been a moment since I've used Dockutil but it's an amazing little utility to quickly set user docks via command line.
Here's a short script below that first checks if Dockutil is installed, installs it if not and sets the user dock to the script below. This is just a starting point, the script can be customized in any number of ways. Please refer to Dockutil's documentation for further customization options.
This command can be run as a JumpCloud command running as root. It'll change the dock for the currently logged in user.
#!/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.0.2/dockutil-3.0.2.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 "/Applications/Google Chrome.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/JumpCloud.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Visual Studio Code.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/PowerShell.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/zoom.us.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Spotify.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "System/Applications/System Preferences.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "~/Downloads" --section others --view auto --display folder --no-restart $UserPlist
echo "Restarting Dock..."
sudo -u $loggedInUser $killall Dock
exit 0
The user's dock should look like this after the script is successfully ran.
12-08-2022 03:00 PM
This is a great utility. Thanks for sharing the script here for others to use. We've been using this for about a year now when setting up new workstations, and it helps speed up that process by automating what would other be a manual task. Sometimes it doesn't work 100% and will not always add all the desired apps. However, even in those instances, it still helps by clearing out the default system apps, so we just have to drag in the missing apps. Not a perfect solution, but still better than doing everything manually!
08-20-2024 11:31 AM
I just tried using this script, as is except modifying the apps and its not working.
Anyone know if these needs to be updated for 14.X?
08-27-2024 10:47 AM
tagging @jworkman - does it need updating for 14.x?
Like someone's post? Give them a kudo!
Did someone's answer help you? Please mark it as a solution.
08-27-2024 03:12 PM - edited 08-27-2024 03:17 PM
It's working for me on 14.16.1. Just make sure to run it as `sudo ./Dockuitl.sh`
#!/usr/bin/env 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.0.2/dockutil-3.0.2.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 Dock..."
sudo -u $loggedInUser $dockutil --add "/Applications/Google Chrome.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Volumes/Preboot/Cryptexes/App/System/Applications/Safari.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Mimestream.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Spark.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Calendar.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Reminders.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/Messages.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Slack.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Evernote.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/1Password.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/iTerm.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Visual Studio Code.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Sourcetree.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/Postman.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/App Store.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/System Settings.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "~/Developer/" --view grid --display folder --no-restart $UserPlist
echo "Restarting Dock..."
sudo -u $loggedInUser $killall Dock
exit 0
New to the site? Take a look at these additional resources:
Ready to join us? You can register here.