Mavericks 10.9.3 + Dock Management

Kennedy
New Contributor II

Greetings.

Trying to manage dock items with Mavericks and Dockutil 2.0.0 is "doing my head in".

Is anyone out there successfully achieving this?

Here's a rundown;

Dock management working perfectly in 10.8.x with Dockutil 1.1.2. I can add/remove/move dock items at login with a script until my heart is content - absolutely perfect functionality.

Totally inconsistent results using Dockutil 2.0.0 on Mavericks. An example of the commands I'm using in my script:

/usr/local/bin/dockutil --remove all "/home/$3";
    /usr/local/bin/dockutil --add '/Applications/iMovie.app' --section apps "/home/$3";
    /usr/local/bin/dockutil --add '/Applications/GameSalad.app' --section apps "/home/$3";
    /usr/local/bin/dockutil --add '/Applications/Self Service.app' --section apps "/home/$3";
    /usr/local/bin/dockutil --add /Applications --view grid --display folder --section others "/home/$3";
    /usr/local/bin/dockutil --add /home/$3/Downloads --view grid --display folder --section others "/home/$3";
    /usr/local/bin/dockutil --add /home/$3/Documents --view grid --display folder --section others "/home/$3";
    /usr/local/bin/dockutil --add /Volumes/shared --view grid --display folder --section others "/home/$3";

What I'm seeing is totally unpredictable results. One login will add, say, Self Service and the Downloads folder. Then I'll log out and log back in and the iMovie and Applications folders are there, but nothing else.

If I publish the same script in self service and run it once I'm logged in, I get a new dock icon each time I run it, and not necessarily in the order that I want. Eventually all dock icons are present.

I have read extensively on the new cached preferences model, and how it works etc. I'm monitoring the com.apple.dock.plist file and what's being written to that file is consistent with the above findings.

Just wondering if I'm doing something wrong, or if there might be a bug in 10.9.x(3?) and Dockutil 2.0.0

Would love to hear what others are doing in this regard and I'm open to other ideas. I'm happy to forego control of the dock, but the last 4 items I'm adding to the "others" section are deal breakers - I need them on there.

Cheers!

Gav

19 REPLIES 19

donmontalvo
Esteemed Contributor III

Hi @Kennedy, might want to post these issues/questions to Kyle Crawford's Github page, not sure he monitors this forum:

https://github.com/kcrawford/dockutil/issues

--
https://donmontalvo.com

Kennedy
New Contributor II

No worries - I will submit over there if I don't have any luck.

I was hoping some others on here might be willing to post their dockutil scripts, particularly if they're working well with 10.9.x.

Cheers,
Gav

scottb
Honored Contributor

@Kennedy: For kicks, have you tried 1.1.4?

Kennedy
New Contributor II

Yep, tried all previous versions.

mm2270
Legendary Contributor III

I was going to ask the same as @boettchs - if you tried version 1.1.4. Though we don't use dockutil to set up a whole Dock, we've used it successfully to add individual Dock icons in policies under 10.9.
If you have tried that version and are having the same issue, I'll start off by saying that Mavericks introduced a ton of headaches in regards to managing certain preferences. Apple, in my opinion, went completely overboard with the aggressiveness of the caching model. I've found at times I need to go through near herculean efforts to get the OS to recognize changes ON DISK rather than pulling from its cache. So this is partially the issue you're seeing.

That said, the only real suggestion I can make is to add the --no-restart flag to each of the commands, except for the final change. Each one of those will be restarting the Dock process unless you tell it not to. This was true at least as of version 1.1.4. Haven't' looked close enough at 2.0.0 to know if that's still true. If it is, I don't think Mavericks takes too kindly to being told to restart the Dock process more than one or two consecutive times. I have a feeling it simply ignores any subsequent "restart the Dock" directives, which may be why the icons are showing up so inconsistently.

scottb
Honored Contributor

And to add to more questions based on what @mm2270 said, does a restart of the Mac or logout/login get things working? The caching of prefs and changes in 10.9 as stated sucks. Wondering if the above alleviates this or if it just doesn't work?

Not applicable

+1 for mm270's suggestion on adding --no-restart. I found dockutil 1.1.4 to be much better behaved and predictable on 10.8.5 & 10.9.2 when you only let it restart the Dock on the final change.

Kennedy
New Contributor II

Thanks everyone. Will try a few of these suggestions in the morning!

Cheers,
Gav

Kennedy
New Contributor II

Hi all,

I have found a resolution for this. I'm heading overseas now, but will post the issue/resolution and also my Dockutil script on Monday, in case others run into the same issue.

Very much appreciate all of the ideas etc.

Cheers,
Gav

fabian_ulmrich
Contributor

Hi @Kennedy][/url

I am using dockutil v1.14 with the following simple script and it works fine with OS 10.9.3. May you give it a try!

#!/bin/bash
# Setting User Dock Items


# Variables
LoggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
PLIST="/Users/$LoggedInUser/Library/Preferences/com.apple.dock.plist"
JSSAdmin="" # Set your JSS Management Accounthere
logger="/usr/bin/logger"


if [ ${LoggedInUser} != "${JSSAdmin}" ]; then

sleep 10

    # Set Dock Items for current user
    ${logger} "___Setting Dock Items for user ${LoggedInUser}"
    /Library/Application Support/JAMF/bin/dockutil.py --remove all "${PLIST}"

    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Self Service.app" --position beginning  "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Launchpad.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Safari.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Mail.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Contacts.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Calendar.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Notes.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Maps.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/iPhoto.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/iWork '09/Pages.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/iWork '09/Keynote.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/iWork '09/Numbers.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Microsoft Office 2011/Microsoft Word.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Microsoft Office 2011/Microsoft Powerpoint.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Microsoft Office 2011/Microsoft Excel.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/iTunes.app" "${PLIST}"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/System Preferences.app" "${PLIST}"

else

    # Set Dock Items for Management User
    ${logger} "___Setting Dock Items for user Management User"
    /Library/Application Support/JAMF/bin/dockutil.py --remove all "/var/ladmin/Library/Preferences/com.apple.dock.plist"

    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Self Service.app" --position beginning  "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Safari.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Utilities/Terminal.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Utilities/Console.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Utilities/Activity Monitor.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/Utilities/System Information.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"
    /Library/Application Support/JAMF/bin/dockutil.py --add "/Applications/System Preferences.app" "/var/${JSSAdmin}/Library/Preferences/com.apple.dock.plist"

fi

exit 0

Also you could try to delete the users dock.plist file as well as the dock caching file, which can be found under "~/Library/Application Support/Dock/someweirdnumbersfile.db". After you deleted them, restart or logout/in.

Hope that helps.

Cheers!

jaronbrass
New Contributor

Kennedy,

Can you post what you used to resolve this? It's incredibly frustrating to say the least.

Thanks!

MichaelC
New Contributor III

I don't know how Kennedy solved it, but I was seeing much the same behaviour until I added " && sleep 1" at the end of every call to dockutil except the last, which is also the only call that reboots the dock. It slows the login down a bit, but at least the dock is consistent.

Kennedy
New Contributor II

My apologies for not posting our solution as promised. I'm away on work until Tuesday, but will make an effort when I return to share the scripts we're using.

Cheers,
Gavin

jaronbrass
New Contributor

Gavin,

Thanks. Looking forward to seeing your solution. What we're trying to accomplish at a very simple level is to add Microsoft Office icons to the dock on systems with Office installed. We have a smart computer group that detects Office and a policy applied to it to run once per computer on login. That policy is running the below script:

#!/bin/sh

user=$3

/usr/sbin/dockutil --add '/Applications/Microsoft Lync.app' --no-restart "/Users/$user" && sleep 2
/usr/sbin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Word.app' --no-restart "/Users/$user" && sleep 2
/usr/sbin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Outlook.app' --no-restart "/Users/$user" && sleep 2
/usr/sbin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Excel.app' --no-restart "/Users/$user" && sleep 2
/usr/sbin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft PowerPoint.app' "/Users/$user"

I added the "&& sleep x" per Carey's suggestion, but we still see icons applying inconsistently. First login gets maybe one or two, subsequent logins add more, until about the 3rd or 4th login. (I switched the policy to ongoing for testing.)

Our default user template has a simple dock (Self Service, System Preferences, Safari, ~/Documents stack, ~/Downloads stack, URL to help desk). The goal here is to have icons added depending on a configuration we use. Some users get Office, others don't. Our Engineering configuration would add Office icons plus others, etc. I could create a default dock and push to the DUT per configuration, but that gets messy.

Basically, we want to be able to image a machine and deploy to a user without IT configuration. We also allow users to 'refresh' their machines at their desks if they so desire. Everything is working, except this.

Also I tried using Casper's own ability to add the icons to the dock in a similar policy, but noticed that on the first login (by a network user - we're bound to AD with Centrify) the Dock would completely reset to the defaults stored within the default.plist file inside Dock.app. Still not sure why. It was working properly at some point, and now doesn't, so I'm back to dockutil again.

jacob_salmela
Contributor II

I set the entire dock for all users with a single script. This works well because we use local users and there are only a few. Using dockutil 1.1.4 without the --no-restart option usually works for me, but I have been experimenting with it. The nice thing is that dockutil can still reset the dock even with a config profile that makes dock changes immutable. That way, students cannot mess up the dock.

#!/usr/bin/python
#-----------IMPORTS----------
from subprocess import call
from platform import mac_ver
from socket import gethostname

#----------VARIABLES---------   
# Define users 
admin_user = "/Users/admin"
student_user = "/Users/student"


# Apps that every user should get, regardless of role
all_user_apps   = ["/Applications/Safari.app",
                           "/Applications/Firefox.app",
                           "/Applications/Google Chrome.app"
                           ]    

# Apps specific to the admin users
admin_apps = ["/Applications/Utilities/Console.app",
                        "/Applications/Utilities/Disk Utility.app",
                        "/Applications/Utilities/Terminal.app",
                        "/Applications/System Preferences.app",
                        "/Applications/Utilities/Activity Monitor.app",
                        "/Applications/Utilities/Migration Assistant.app"
                        ]   

# Find the computer name and split it into a list using '-' as a delimiter
# This is used to check the computer name and compare it to a list of the required dock items for the room it belongs to
# Our naming convention is Building-Room-Number, so it is easy to split up
computer_name = gethostname().split('-')

# Store OS X version in format of 10.x
# To be used for version-specific apps
v, _, _ = mac_ver()
v = float('.'.join(v.split('.')[:2]))

# Locations where specific apps need to be installed based on room
# Use computer_name[index] to print out the correct field for the room
s191     =  "S191"        # Use computer_name[1]
s152 =  "S152"        # Use computer_name[1]

#----------FUNCTIONS---------           
##########################
def dockutil_remove(user):
    # Removes all dock items for a clean start
    #call(["/usr/bin/dockutil", "--remove",  "all", user])
    # Experimenting with using --no-restart option
    call(["/usr/bin/dockutil", "--no-restart", "--remove",  "all", user])
    print "****REMOVED ALL APPS for " + user 
    print "  **DOCK WILL NOW BE SET for " + user 

#################################
def dockutil_add(app_list, user):
    for app in app_list:
        print "   *ADDING " + app
        #call(["/usr/bin/dockutil", "--add", app, user])
        call(["/usr/bin/dockutil", "--no-restart", "--add", app, user])

#############################
def set_dock(app_list, user):
    dockutil_remove(user)
    # Add apps that all users get first
    dockutil_add(all_user_apps, user)
    # Then add any additional apps that that the user requires
    # Doing it in this order ensures a consistent dock from left-to-right
    dockutil_add(app_list, user)

############################
def add_loc_specific_apps():
    if (computer_name[1] == s191):
        print "****" + computer_name[1] + " detected****" 
        set_dock(all_user_apps, student_user)
    elif (computer_name[1] == s152):
        print "****" + computer_name[2] + " detected****" 
        set_dock(s152_apps, student_user)
        set_dock(s152_apps, some_other_user)
    elif (computer_name[1] == training_lab):
        print "****" + computer_name[2] + " detected****" 
        set_dock(some_app_list, some_user)
    elif (computer_name[2] == main_office):
        print "****" + computer_name[2] + " detected****" 
        set_dock(some_app_list, another_user)
    else:
        # Student user exists on all computers so if nothing else worked, the dock will get set for them
        set_dock(all_user_apps, student_user)
        print "*NO LOCATION-SPECIFIC APPS needed"

#------------------------------     
#-------BEGIN SCRIPT-----------
#------------------------------ 
set_dock(admin_apps, admin_user)
add_loc_specific_apps()
call(["/usr/bin/killall", "Dock"])

Kennedy
New Contributor II

Hi all,

This is the script I'm using at the moment. Not as well written as Jacobs, but works perfectly for us.

Hope it helps someone.

Cheers,
Gavin

#!/bin/bash

# Log the script output to jamf.log for easier viewing
logfile=/var/log/jamf.log;
exec> $logfile 2>&1;

# Script header (for viewing in the jamf.log)
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: ";
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: ---------------------------------------------------------------------------------------------";
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: --- Starting student_dock_localhome_10.9.3.sh -----------------------------------------------";
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: ";

# Ping the internal IP of the JSS, otherwise do nothing
if ping -c 1 -W 1 1.2.3.4 > /dev/null

then

    # We can contact the JSS, so proceed with adding the dock items
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Can ping 10.0.1.76 - proceeding.";

    # Set the currently logged in user variable
    LoggedInUser=$3;
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Logged in user: $LoggedInUser";

    # Set the plist location for the dock
    PlistLocation="/Users/$LoggedInUser/Library/Preferences/com.apple.dock.plist";
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Plist Location: $PlistLocation";

    # Remove all items from the dock
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Removing all dock items";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --remove all "${PlistLocation}";
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Removed all dock items";

    # Add the dock items in the following order
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Adding dock items";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Launchpad";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Launchpad.app' --replacing "Launchpad" --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Safari";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Safari.app' --replacing "Safari" --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Photo Booth";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Photo Booth.app' --replacing "Photo Booth" --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding iTunes";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/iTunes.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Microsoft Word";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Word.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Dreamweaver";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Dreamweaver CC/Adobe Dreamweaver CC.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Fireworks";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Fireworks CS6/Adobe Fireworks CS6.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Flash";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Flash CC/Adobe Flash CC.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Illustrator";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Illustrator CC/Adobe Illustrator.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Photoshop";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Photoshop CC/Adobe Photoshop CC.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Adobe Premiere Pro";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Adobe Creative Cloud/Adobe Premiere Pro CC/Adobe Premiere Pro CC.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Inspiration";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Inspiration 9.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Comic Life 2";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Comic Life 2.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding GarageBand";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/GarageBand.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding iMovie";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/iMovie.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding GameSalad";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/GameSalad.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Self Service";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add '/Applications/Self Service.app' --section apps "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Applications folder";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add /Applications --view grid --display folder --section others "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Downloads folder";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add /Users/$LoggedInUser/Downloads --view grid --display folder --section others "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Documents folder";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add /Users/$LoggedInUser/Documents --view grid --display folder --section others "${PlistLocation}";

    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]:  -Adding Student Shared folder";
    sudo -u $LoggedInUser /usr/local/bin/dockutil --add /Volumes/student_shared --view grid --display folder --section others "${PlistLocation}";

else

    # Cannot contact the JSS, so do nothing
    echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: Cannot ping 10.0.1.76 - skipped adding items.";

fi

# Script footer (for viewing in the jamf.log)
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: --- Finished student_dock_localhome_10.9.3.sh -----------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: ---------------------------------------------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[bcgs_script]: "

# Exit the script
exit

nigelg
Contributor

I am using the jamf modifyDock command for dock management.

I start with an empty dock in the User template folder and add the items I need based on the JSS ID - all the dock items are stored in the JSS. I have commented out the removal lines - they are mainly there for reference if I want to adjust the script.

i also delete the dockfixup file which loves to stick iBooks and Maps in to the dock whatever happens. Very annoying and took me a while to work out that it wasn't caching preferences that were causing it.

#!/bin/sh

#removes file that populates dock with maps and ibooks
rm /Library/Preferences/com.apple.dockfixup.plist

#Script removes Dock Items first

#jamf modifyDock -id 2 -remove -leaveRunning #LaunchPad
#jamf modifyDock -id 3 -remove -leaveRunning #Safari
#jamf modifyDock -id 4 -remove -leaveRunning #Mail
#jamf modifyDock -id 5 -remove -leaveRunning #Contacts
#jamf modifyDock -id 6 -remove -leaveRunning #Calendar
#jamf modifyDock -id 7 -remove -leaveRunning #Notes
#jamf modifyDock -id 8 -remove -leaveRunning #Maps
#jamf modifyDock -id 9 -remove -leaveRunning #Messages
#jamf modifyDock -id 10 -remove -leaveRunning #Facetime
#jamf modifyDock -id 11 -remove -leaveRunning #Photo Booth
#jamf modifyDock -id 12 -remove -leaveRunning #iTunes
#jamf modifyDock -id 13 -remove -leaveRunning #iBooks
#jamf modifyDock -id 14 -remove -leaveRunning #Appstore
#jamf modifyDock -id 15 -remove -leaveRunning #System Preferences
#jamf modifyDock -id 16 -remove #Applications



jamf modifyDock -id 37 -beginning -leaveRunning #PhotoShop CC 2014
jamf modifyDock -id 16 -beginning -leaveRunning #Applications
jamf modifyDock -id 2 -beginning -leaveRunning #LaunchPad
jamf modifyDock -id 3 -beginning #Safari




exit 0

Kennedy
New Contributor II

Hi all,

I've been working on our dock script today and have taken some ideas from jacob_salmela's script. Mainly the use of functions and also to achieve one dock script for our entire environment. The dock items will be determined by the Parameter 4 value. The plist location changes depending on local home or network home, and we tell the script about this in Parameter 5.

I'm sure this could be optimized, and I'm open to any comments, however we were in a bit of a hurry to write this.

Script attached.

Cheers,
Gavin

#!/bin/bash


#log the output of the script to the jamf.log for easy viewing
logfile=/var/log/jamf.log
exec> $logfile 2>&1





#------------------------------     
#-------BEGIN VARIABLES--------
#------------------------------ 

#path to dockutil
dockutil_path='/usr/local/bin/dockutil'

#set LoggedInUser as the current user
if [ `ls -l /dev/console | cut -d " " -f 4` == "root" ]
then
    #script is run at login, so the user is the $3 variable
    LoggedInUser=$3
else
    #script is run as self service, so the user is not sent to the script
    LoggedInUser=`ls -l /dev/console | cut -d " " -f 4`
fi

#set the plist location depending on whether local home or network home is used
if [ "$5" == "local" ]
then
    #policy is for local home folder
    PlistLocation="/Users/$LoggedInUser/Library/Preferences/com.apple.dock.plist"
fi
if [ "$5" == "network" ]
then
    #policy is for network home folder
    PlistLocation="/home/$LoggedInUser/Library/Preferences/com.apple.dock.plist"
fi

#------------------------------     
#-------END VARIABLES----------
#------------------------------ 





#------------------------------     
#-------BEGIN FUNCTIONS--------
#------------------------------             

#this function adds an item to the dock. It takes 8 parameters;
# $1 = Sudoers username
# $2 = Position of dock item in the dock
# $3 = Dock item path
# $4 = Dock item display name
# $5 = Dock item view mode (Fan, Grid, List, Auto)
# $6 = Dock item display mode (Folder, Stack)
# $7 = Dock item section (Apps, Other)
# $8 = com.apple.dock.plist location
function add_to_dock()
{
    #return the result of the dockutil --find command to allow us to determine if the dock item is already in the dock.
    dock_item_find=`sudo -u $1 $dockutil_path --find "$4" $8`

    #if the dock item is found then don't try and add it again
    if [[ $dock_item_find == *was found* ]]
    then
        #dock item is found
        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Skipping '$4' (Item already in dock)."
    else
        #dock item is not found

        #add the dock item to the right location on the dock
        if [[ $7 == "apps" ]]
        then
            #add the dock item to the apps section
            echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Adding '$4' to the $7 section."
            sudo -u $1 $dockutil_path --add "$3" --section $7 $8;
        fi
        if [[ $7 == "others" ]]
        then
            #add the dock item to the others section
            echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Adding '$4' to the $7 section."
            sudo -u $1 $dockutil_path --add "$3" --view $5 --display $6 --section $7 $8;
        fi
    fi

    #check if the dock item is in the dock before trying to move it to the right location
    dock_item_find=`sudo -u $1 $dockutil_path --find "$4" $8`

    #if the dock item is found in the dock then move it, otherwise don't try and move a dock item that isn't there.
    if [[ $dock_item_find == *was found* ]]
    then
        #dock item found, move to position.
        move_to_position "$1" "$4" "$2" $8 
    else
        #dock item not found, don't try and move it
        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Cannot move $4 to position $2 (Item not in dock)."
    fi
}

#this function moves a dock item to a position in the dock. It takes 3 parameters;
# $1 = Sudoers username
# $2 = Dock item display name
# $3 = Position
# $4 = com.apple.dock.plist location
function move_to_position()
{
    echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Moving '$2' to postition $3."
    sudo -u $1 $dockutil_path --move "$2" --position $3 $4;
}    

#this function removes all items from the dock. It takes 1 parameter;
# $1 = com.apple.dock.plist Location
function clear_dock()
{
    echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:  -Removing all items from the dock."
    $dockutil_path --remove all $1    
}    

#------------------------------     
#-------END FUNCTIONS----------
#------------------------------ 





#------------------------------     
#-------BEGIN SCRIPT-----------
#------------------------------ 

#output some information to the jamf.log for debugging.
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: ---------------------------------------------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: --- Starting dock.sh ------------------------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Policy variables:" 
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:    $3 = $3"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:    $4 = $4"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:    $5 = $5"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: " 
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Script variables:" 
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:    $LoggedInUser =  $LoggedInUser"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:    $PlistLocation = $PlistLocation"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]:"

#self service policy to reset the dock to the T3 settings.
if [ $4 == "t3-reset-default-dock" ]; then
    if ping -c 1 -W 1 10.0.1.76 > /dev/null
    then

        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Can ping 10.0.1.76 - resetting the dock."

        #clear the dock
        clear_dock $PlistLocation

        #add apps
        add_to_dock $LoggedInUser 1 "/Applications/Safari.app"                                     "Safari"            "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 2 "/Applications/iTunes.app"                                     "iTunes"            "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 3 "/Applications/Microsoft Office 2011/Microsoft Word.app"       "Microsoft Word"    "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 4 "/Applications/Inspiration 9.app"                              "Inspiration 9"     "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 5 "/Applications/Self Service.app"                               "Self Service"      "" "" "apps" $PlistLocation

        #add others
        add_to_dock $LoggedInUser 1 "/Applications"                                                "Applications"      "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 2 "/home/$LoggedInUser/Downloads"                                "Downloads"         "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 3 "/home/$LoggedInUser/Documents"                                "Documents"         "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 4 "/Volumes/student_shared"                                      "student_shared"    "grid"  "folder"    "others"    $PlistLocation

    else
        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Cannot ping 10.0.1.76 - not resetting the dock."
    fi
fi

#login policy to ensure basic dock items are in the dock and in the correct location
if [ $4 == "t3-dock" ]; then

    if ping -c 1 -W 1 10.0.1.76 > /dev/null
    then
        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Can ping 10.0.1.76 - adding all items to dock."

        #add apps
        add_to_dock $LoggedInUser 1 "/Applications/Safari.app"                                     "Safari"            "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 2 "/Applications/iTunes.app"                                     "iTunes"            "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 3 "/Applications/Microsoft Office 2011/Microsoft Word.app"       "Microsoft Word"    "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 4 "/Applications/Inspiration 9.app"                              "Inspiration 9"     "" "" "apps" $PlistLocation
        add_to_dock $LoggedInUser 5 "/Applications/Self Service.app"                               "Self Service"      "" "" "apps" $PlistLocation

        #add others
        add_to_dock $LoggedInUser 1 "/Applications"                                                "Applications"      "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 2 "/home/$LoggedInUser/Downloads"                                "Downloads"         "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 3 "/home/$LoggedInUser/Documents"                                "Documents"         "grid"  "folder"    "others"    $PlistLocation
        add_to_dock $LoggedInUser 4 "/Volumes/student_shared"                                      "student_shared"    "grid"  "folder"    "others"    $PlistLocation

    else
        echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: Cannot ping 10.0.1.76 - skip adding network items."
    fi
fi

#no policy set in $4, so do nothing
if [ $4 == /dev/null ];then
    echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: $4 is null. Nothing to do."
fi

echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: --- Finished dock.sh ------------------------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: ---------------------------------------------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script_dock.sh]: "

#------------------------------     
#-------END SCRIPT-------------
#------------------------------

slovett
New Contributor

Hi,
I am having the same problem with os 10.9.4. I'm using it in elementary computer labs where multiple students log into the computers throughout the day. The dock icons are inconsistent - some users get all that they should and others are missing. Did you ever find a resolution?
Thanks!