Skip to main content
Question

Extension Attribute to check if an item is in the Dock

  • June 2, 2018
  • 2 replies
  • 23 views

Forum|alt.badge.img+6

We are using Dockutil along with this script to place an smb file share icon in the Dock. This is working just fine
/usr/local/bin/dockutil --add smb://fs1.vcs.local/File Shares --label "File Shares" --position end

What I want to do is check whether this item is in the Dock or not before running this command. Is there an Extension Attribute (along with a Smartgroup) to check if an item is already in the Dock?

2 replies

Forum|alt.badge.img+5
  • Contributor
  • June 4, 2018

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

howie_isaacks
Forum|alt.badge.img+23
  • Esteemed Contributor
  • December 14, 2023

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>"