This is what I use. I start by removing everything from the dock then adding what I desire. Be mindful some Applications' paths changed in Monterey/Ventura. It may be easiest to just drag the Application to Terminal then copy the path. One example would be "/System/Applications/ System Settings.app" (Also, this is called Settings in Ventura instead of Preferences)
*I realize I should not need sudo when pushing from Jamf.
#!/bin/bash
USERNAME=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
dockutil="/usr/local/bin/dockutil"
#remove stuff
sudo -u $USERNAME $dockutil --remove all --no-restart --allhomes
#add stuff
sudo -u $USERNAME $dockutil --add '/Applications/Self Service.app' --no-restart --allhomes
#kill Dock
sudo killall Dock
We don't want to remove anything, we just want to add self service, i removed the section about #remove stuff. but this then added self service which is great, but removed everything else.
Here is a more complete view of how I am using this.
We use the Remove feature to trim down the Music, AppleTV, PodCasts, etc apps.
USERNAME=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
dockutil="/usr/local/bin/dockutil"
#remove stuff
sudo -u $USERNAME $dockutil --remove all --no-restart --allhomes
#add stuff
sudo -u $USERNAME $dockutil --add '/System/Applications/Launchpad.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Self Service.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Google Chrome.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Microsoft Excel.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Microsoft Word.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Microsoft PowerPoint.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/Slack.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/Applications/zoom.us.app' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '/System/Applications/System Settings.app' --no-restart --allhomes
#add folders
sudo -u $USERNAME $dockutil --add '/Applications/' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '~/Downloads/' --no-restart --allhomes
sudo -u $USERNAME $dockutil --add '~/Documents/' --no-restart --allhomes
#kill Dock
sudo killall Dock
Are you triggering your Dock script at login? If so, it helps to add code to your Dock script to have it not do anything until the Dock is actually loaded. Put this ahead of any of your dockutil commands. Here is what I use:
# Don't do anything until the Dock has started
if [[ ! $(pgrep -x Dock) ]]; then
until [[ $(pgrep -x Dock) ]]; do
echo "Dock not started. Waiting 1 second..."
sleep 1
done
echo "Dock started at: $(date +"%r")"
else
echo "Dock already started"
fi
Thanks all for your help, I have now managed to get this working.