You are likely editing the wrong dock plist depending on how dockutil is being called or depending on how the $3 is resolving, or something else like that.
Try this:
#!/bin/bash
# Include Standard PATH for commands
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
whoami="/usr/bin/whoami"
echo="/bin/echo"
python="/usr/bin/python"
sudo="/usr/bin/sudo"
dockutil="/usr/local/bin/dockutil"
killall="/usr/bin/killall"
loggedInUser=$($python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')
##########################################################################################
# Check if script is running as root
##########################################################################################
$echo
if [ `$whoami` != root ]; then
$echo "[error] This script must be run using sudo or as root. Exiting..."
exit 1
fi
##########################################################################################
# Use Dockutil to Modify Logged-In User's Dock
##########################################################################################
$echo "----------------------------------------------------------------------"
$echo "Use Dockutil to Modify Logged-In User's Dock"
$echo "----------------------------------------------------------------------"
$echo
$echo "Removing all Items from the Logged-In User's Dock..."
$sudo -u $loggedInUser $dockutil --remove all --no-restart
$echo "Creating New Dock..."
$echo
$echo "Adding "Finder"..."
$echo "Adding "Google Chrome"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Google Chrome.app" --no-restart
$echo "Adding "Microsoft Word"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Microsoft Word.app" --no-restart
$echo "Adding "Microsoft Excel"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Microsoft Excel.app" --no-restart
$echo "Adding "Calculator"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Calculator.app" --no-restart
$echo "Adding "Dashboard"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Dashboard.app" --no-restart
$echo "Adding "VMware Horizon Client"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Vmware Horizon Client.app" --no-restart
$echo "Adding "Photos"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Photos.app" --no-restart
$echo "Adding "iTunes"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/iTunes.app" --no-restart
$echo "Restarting Dock..."
$sudo -u $loggedInUser $killall Dock
exit 0
Oh also, I suggest pulling the commit of Dockutil from GitHub because there have been a few bug fixes added.
I am already running Dockutil 2.0.5 which is the latest. I tried the script provided and it sets the Dock correctly but I can still not add items or remove items from the Dock and make it stick. A log off and back and the Dock is back to the default set by Dockutil.
Other ideas?
I figured it out. I had another policy that runs that add a single item to the Dock. This policy was set to run every time a user logged in. Basically I wanted to make sure one item was always in the Dock. The script behind this other policy was the root cause of the problem. Once I fixed that script, everything worked fine.