Since extension attributes are per-machine, and since docks are per-user, you'd either have an extension attribute that was just the last user's dock or you could do one that looked at every user's dock instead. Both of which would be pretty easy, but not exactly what you are looking for.
Could you just wrap that command in an IF to only run it if it was missing? Here's an example I've used for Self-Service, but easily changed for this purpose.
#!/bin/bash
user="$(stat -f%Su /dev/console)"
#Check to see if dockutil is installed, exit if not.
DOCKUTIL=/usr/local/bin/dockutil
if [[ ! -e $DOCKUTIL ]];
then
echo "Dockutil not installed!"
exit 1
fi
#Check if Self-Service is already in the dock
$DOCKUTIL --find "Self Service" "/Users/$user/"
if [[ $? == 1 ]];
then
echo "Self Service not in $user's dock. Adding."
$DOCKUTIL --add '/Applications/Self Service.app' "/Users/$user/"
else
echo "Self Service is in $user's dock already."
exit 0
fi
This thread is old but I wanted to contribute to this. I created this EA recently. It has been working for me. Since this is a user level preference, the step to read com.apple.Dock is done as the current logged in user.
#!/bin/zsh
# Who is the current user?
currentUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
# Is Self Service in the Dock?
ssinDock=$(sudo -u "$currentUser" defaults read com.apple.Dock | grep "com.jamfsoftware.selfservice.mac" | /usr/bin/awk '{print $3}' | sed 's/[;"]//g')
if [ $ssinDock = "com.jamfsoftware.selfservice.mac" ]; then
SS="Yes"
echo "Self Service is in the Dock"
else
SS="No"
echo "Self Service is not in the Dock"
fi
echo "<result>$SS</result>"