cancel
Showing results for 
Search instead for 
Did you mean: 

Using Dockutil to set a user's dock

jworkman
JumpCloud Employee
JumpCloud Employee

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.

Screen Shot 2022-12-06 at 1.49.07 PM.png

 

 

 

1 REPLY 1

NVergin
Rising Star II

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!