cancel
Showing results for 
Search instead for 
Did you mean: 
Disclaimer
JUMPCLOUD EXPRESSLY DISCLAIMS ALL REPRESENTATIONS, WARRANTIES, CONDITIONS, AND LIABILITIES OF ANY KIND ARISING FROM OR RELATED TO THIRD-PARTY SOFTWARE, SCRIPTS, REPOSITORIES, AND APIS. JUMPCLOUD IS NOT REQUIRED TO SUPPORT ANY SUCH THIRD-PARTY MATERIALS AND ALL RISKS RELATED TO THIRD-PARTY MATERIALS ARE YOUR RESPONSIBILITY. PLEASE ALSO REVIEW THE JUMPCLOUD TOS.

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

 

 

 

6 REPLIES 6

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!

rocrusso
Novitiate II

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?

BScott
Community Manager Community Manager
Community Manager

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.

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

 

Screenshot 2024-11-13 at 10.04.44 AM.pngwould you be able to tell me what I have wrong in my set up @jworkman

I have this script set up as a command in JumpCloud

I have my trigger as "Next Login" 

This is the scrip, I am copy and pasting what you have above and just modifying the apps to show in dock.

The dock does restart - it goes away then comes back. When it comes back, nothing changes.

Here is what i have:

#!/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 "/Applications/Preview.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/Applications/zoom.us.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "/System/Applications/System Settings.app" --no-restart $UserPlist
sudo -u $loggedInUser $dockutil --add "~/Downloads/" --view grid --display folder --no-restart $UserPlist
echo "Restarting Dock..."
sudo -u $loggedInUser $killall Dock
exit 0

rocrusso
Novitiate II

I did update the script to grab version 3.1.3 but same results

I get this from results... Trace/BPT: 5 errors

dockutil could not be found, installing...
installer: Package name is 
installer: Installing at base path /
installer: The install was successful.
------------------------------------------------------------------------
Current logged-in user: XXX
------------------------------------------------------------------------
Removing all Items from the Logged-In User's Dock...
Creating Dock...
Restarting Dock... 
bash: line 29:  1852 Trace/BPT trap: 5       sudo -u $loggedInUser $dockutil --add "/Applications
/Google Chrome.app" --no-restart $UserPlist
Notice: adding item at /System/Applications/Preview.app rather than /Applications/Preview.app
bash: line 30:  1892 Trace/BPT trap: 5       sudo -u $loggedInUser $dockutil --add "/Applications
/Preview.app" --no-restart $UserPlist
bash: line 31:  1960 Trace/BPT trap: 5       sudo -u $loggedInUser $dockutil --add "/Applications
/zoom.us.app" --no-restart $UserPlist
bash: line 32:  1970 Trace/BPT trap: 5       sudo -u $loggedInUser $dockutil --add "/System/Appli
cations/System Settings.app" --no-restart $UserPlist
bash: line 33:  2160 Trace/BPT trap: 5       sudo -u $loggedInUser $dockutil --add "~/Downloads/"
 --view grid --display folder --no-restart $UserPlist