Managed Preferences - Arranging Dock Items

NateW
New Contributor III

I am getting a standard configuration setup and I was curious how people arranged their docks.

With OD MCX, you just drag and drop them into the order you want in WGM and it applies the icons in that order.

What is the best way to manage a dock via Casper and make sure the Icon are in the correct order? It seems like it sorts them alphabetically when I add Dock Items into a Policy. I've also tried importing a com.apple.dock.plist into Managed Preferences and it didn't like the nested Dicts.

1 ACCEPTED SOLUTION

pat_best
Contributor III

We were unable to efficiently use MCX (in Casper) to manage dock items/order so we found a few alternate methods. As far as I know, Casper is not able to perform dock arrangement in MCX.

Which OS(s) are you applying the dock to?

With Casper 8.4 you can create "deployment profiles" that set up just like an iOS profile and set your order that way.

Using a Casper "dock item" policy does not set any order to your dock. If you run the policy on all of your machines at the same time, you will get similar results, however if you run the policy on 10 machines then wait an hour and run it on ten more, you will most likely get a very different order.

Another possibility is to build the dock on a test machine and capture it using composer with the "user environment" option. This will capture your order as well.

Depending on when you want to apply dock changes in relation to user creation there are other possible issues that can arise.

Hope this helps a little!

Pat B.
Springfield Public Schools

View solution in original post

11 REPLIES 11

pat_best
Contributor III

We were unable to efficiently use MCX (in Casper) to manage dock items/order so we found a few alternate methods. As far as I know, Casper is not able to perform dock arrangement in MCX.

Which OS(s) are you applying the dock to?

With Casper 8.4 you can create "deployment profiles" that set up just like an iOS profile and set your order that way.

Using a Casper "dock item" policy does not set any order to your dock. If you run the policy on all of your machines at the same time, you will get similar results, however if you run the policy on 10 machines then wait an hour and run it on ten more, you will most likely get a very different order.

Another possibility is to build the dock on a test machine and capture it using composer with the "user environment" option. This will capture your order as well.

Depending on when you want to apply dock changes in relation to user creation there are other possible issues that can arise.

Hope this helps a little!

Pat B.
Springfield Public Schools

wangl2
Contributor

I used the second option Pat suggested.
Capture the dock items on the test or reference computer, using Casper Composer to create a .dmg file (under user environment). Then deploy this dock DMG via policy or when imaging. When my AD users log on, they get the same docking. And I use MCX to disable changes to Dock items. The last thing I couldn't figure it out is that because it is a system level MCX, when my local admin account logs in, docks are also locked. I would prefer when my admin logs in, there is no MCX applied.

NateW
New Contributor III

Thanks for the responses guys. That is exactly what I was looking for.

I am moving our machines to Lion, so I can use config profiles once I've migrated them all. I'll use dock method #2 until then.

John_Wetter
Release Candidate Programs Tester

Otherwise, you create a custom MCX and paste in the xml for the dock.plist that you want there. Kinda ugly and prone to errors. Config profiles should do the trick though in Lion. On the 10.6 side, we have a few techs doing it both ways (MCX and a DMG).

jacob_salmela
Contributor II

This year, I used MCX for the dock items and edited the XML manually when a new dock item needed to be added. This works very nice because you can quickly make changes.

Creating packages with composer for the docks works well, but it is a little more difficult and slower if new apps need to be added to the dock--you need to remake the package in order to apply the changes.

One downfall I cannot seem to get around is that is applies to all users, and the MCX settings are difficult to remove.

nkalister
Valued Contributor

dockutil! best way to manage docks, imho
https://github.com/kcrawford/dockutil#readme

mm2270
Legendary Contributor III

I was going to comment and mention dockutil as well. But in truth, to get an initial base Dock setting down to the machines, it may make sense to use one of the above mentions methods and push that out, say, during imaging or on first set up, then use dockutil to make future changes, due to its flexibility and wealth of functions. I'm not sure if I'd use dockutil to get a core Dock down to my workstations, since it would involve a number of commands to get to the point I'd want it (unless you happen to be using a pretty stock Dock config)

nkalister
Valued Contributor

dockutil has a remove-all command now.
My initial script runs the remove-all, then adds in only the things I want.
I used to capture the dock config using Composer, but then the folders in the dock had the labels from the account they were captured under, not the labels for the account they're actually running from.
Doing the initial setup with dockutil labels the folders correctly.

jacob_salmela
Contributor II

Here is what I have been working on getting the docks to work with MCX and dockutil. So far, the results have been promising.

MANAGING OS X DOCKS
(SNOW LEOPARD AND LION)
VIA
JAMF, MCX, AND CLI

by
Jacob Salmela
2012

Technology Support Specialist
for
Hopkins High School
Minnetonka, MN

Last updated: 15 June 2012

Requirements
00. Composer Mac (The Mac used to create packages and scripts)
01. Test Mac (The Mac used to test the packages and installs prior to full-scale deployment)
02. dockutil code https://github.com/kcrawford/dockutil/blob/master/scripts/dockutil
03. Familiarity with OS X
04. Intermediate experience of the command-line interface (CLI) and bash scripting
05. Familiarity with the Casper Suite and JSS

Conceptual Overview
00. Download and install dockutil
01. Create dockutil install package via Casper Composer
02. Deploy package to computers via Casper Remote
03. Create bash script that creates a base dock
04. Create MCX to make the dock immutable
05. Modify the dock over time using Casper Remote or on the local computer using Terminal

Acquire dockutil Source Code
00. On the Composer Mac, go to https://github.com/kcrawford/dockutil/blob/master/scripts/dockutil
01. Highlight and copy the script

Begin a Normal Snapshot in Casper Composer
00. On the Composer Mac, open Casper Composer
01. Choose Normal Snapshot, then click Next
02. Give the package a meaningful name using a naming convention, then click Next.

Note: If there is no naming convention in place, start one, now!

Create the dockutil Application when the Before Snapshot is Complete
00. Open Terminal when the before snapshot is complete
01. Use vi or another text editor to create a new document in /usr/bin called dockutil
02. Paste the code into the document
03. Save the document
04. Type ```
sudo chmod 755 /usr/bin/dockutil
``` then press Enter

Capture the dockutil application in the After Snapshot
00. On the Composer Mac, open Casper Composer
01. Click Create Package Source 02. Click Build as DMG
03. Choose a location to save it, then click Save
04. Make a backup copy

Upload the .DMG to Casper Admin
00. Upload the .DMG to Casper Admin

Deploy the .DMG to the Test Mac via Casper Remote
00. On the Composer Mac, open a new Casper Remote window
01. Check the box next to the Test Mac
02. Click the Packages tab
03. Check the box next to the dockutil package that was uploaded previously
04. Click Go

Verify that the dockutil Installed in the Correct Place
00. On the Test Mac, open Terminal
01. Type ```
ls -l /usr/bin/dockutil
``` then press Enter

Note: If dockutil install correctly, there will be a listing for it after
entering this command.

Run a Simple Command to Ensure dockutil Works Properly
00. On the Composer Mac, open a new Casper Remote window
01. Check the box next to the Test Mac
02. Click the Advanced tab
03. Type ```
dockutil --add /Applications/Calculator.app
``` in the Run Command field
04. Click Go

Note: If dockutil works correctly, the Calculator app will appear on
the logged in user’s dock.

Create a Script that will Set the Default Apps that should be on a User’s Dock
00. On the Composer Mac, open Terminal
01. Create a new script using vi or another text editor
02. Create a script to set a user’s base dock, similar to the one below:

Note: This example script removes all dock items and then adds each new
item in the order it will appear on the dock, hence the sequential commands.

Note: This example script will run as root so the su command is being used. Replace the user david_hayter for the correct username the dock is being made for

Note: The defaults commands are not required, but they help create an aesthetically pleasing dock.

#!/bin/bash
#This script runs dockutil to create a dock for the admin user: david_hayter
#The dock will appear in order the commands are run
#Substitute david_hayter for the username the dock is being made for
#If this is run as root via Casper, the user’s password is not required
#This script can also be pasted into an ARD UNIX command and run as root

su david_hayter -c "/usr/bin/dockutil --remove all"

su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"

su david_hayter -c "/usr/bin/dockutil --add /Applications/Safari.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Firefox.app”

su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"

su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/System Preferences.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Terminal.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Disk Utility.app"
su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Activity Monitor.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Console.app"

su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"

su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Hopkins Software Self Service.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Recon.app"

su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"

su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/AppleScript Editor.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/Java Preferences.app"
su david_hayter -c "/usr/bin/dockutil --add /Applications/TextEdit.app"

su david_hayter -c "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"
  1. Add some optional logic to improve the script’s adaptability and longevity:

    Note: The case command can be used to add different dock items depending on certain criteria. In the example below, it installs either the System Profiler, or System Information depending on the OS version.

    Note: The test command is also used to see if an app exists and adds it
    if it does.

#!bin/bash
#A case statement can be used to install either the System Profiler (in 10.6) or the System Information app (in 10.7)
#This bit of logic makes the script adaptable to two different OS’s

osversion=`sw_vers -productVersion`
case $osversion in
        10.6.[0123456789]) su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/System Profiler.app";;
        10.7.[0123456789]) su david_hayter -c "/usr/bin/dockutil --add /Applications/Utilities/System Information.app";;
        *) ;;
esac

#Another bit of logic uses the test command to see if the Chrome directory exists.  If so, it adds it to the dock, otherwise it does nothing

test -d /Applications/Google Chrome.app
if [ $? = 0 ];then
su david_hayter -c "/usr/bin/dockutil --add /Applications/Google Chrome.app"
fi

Create an MCX Profile to Test the Script and MCX Settings
00. On the Composer Mac, open the JSS Web-interface
01. Navigate to Management > Managed Preferences > Create Managed Preference Profile
02. Enter a Display name
03. Click the Scope tab
04. Add the Test Mac to the scope
05. Click Save

Create an MCX Setting and Profile to Make the Dock Immutable (To everyone except you!)
00. On the Composer Mac, open the JSS Web-interface
01. Navigate to Management > Managed Preferences > Create Managed Preference Create from Template
02. Expand com.apple.dock
03. Click Create next to the Changes Disabled preference
04. Change the value to true
05. Add the preference the profile created in the last step
06. Click Save

Note: The dock will be immutable in the GUI for any user, but items can be added, moved, or removed from the dock via the CLI. dockutil commands can be sent via Casper Remote, ARD, or locally in Terminal.

Bonus: Setting the dock as immutable via MCX provides a consistent dock across the organization. At the same time, dockutil provides the ability to modify the dock, even though it is considered “immutable”.

Bonus: The commands can be sent if the user is logged in or out. If the user is logged in, their dock will restart with the changes made by the command(s). If they are logged out, the new dock will appear at the next login.

Note: If the commands are run locally in Terminal, it will prompt for the user’s password.

Appendix A: List of Useful dockutil Commands
00. Add a dock item

dockutil --add /Applications/Calculator.app

01. Remove a dock item

dockutil --remove ‘Calculator’

02. Add a dock item to the Apps section (left-side of dock)

dockutil --add /Applications/Calculator.app  --section apps

03. Remove a dock item to the Others sections (right-side of dock)

dockutil --remove /Applications/Calculator.app  --section others

04. Add a dock item that replaces an existing item

dockutil --add /Applications/iMovie.app --replacing ‘GarageBand’

05. Move a dock item to another location

dockutil --move ‘Calculator’ --position 7

06. Move a dock item to the beginning of the dock

dockutil --move ‘Calculator’ --position beginning

07. Add a folder to the Others side of the dock

dockutil --add ~/Downloads

08. Add a folder to the Others side of the dock with the grid-style

dockutil --add ~/Downloads --view grid

09. Add a network share to the Others side of the dock

dockutil --add afp://server.domain.com

10. Remove an item from all user docks

dockutil --remove ‘App Store’ --allhomes

11. Add an item right next to another one without knowing the location

dockutil --add /Applications/Firefox --after ‘Firefox’

rmanly
Contributor III

A few tips :)

You shouldn't have all those su -c's and you dont need them.

Dockutil lets you specify the dock you want to change like so:

dockutil --add /Applications/Utilities/Grapher.app /Users/david_hayter/Library/Preferences/com.apple.dock.plist

Just putting /Users/david_hayter is supposed to work as well but it looks like it might be broken in 1.1.2. I have used it before but it is not working on this iMac at the moment... :(

You could even do something like

mydock="/Users/david_hayter/Library/Preferences/com.apple.dock.plist"

Up at the top to make things a bit more readable later on:

dockutil --add /Applications/Utilities/Grapher.app "${mydock}"

For the second script you don't need all those numbers in your case statement.

10.6*)
10.7*)

Will work just fine (incidentally so would [0-9]).

Here is a nicer way to do the Chrome bit as well.

if [[ -d "/Applications/Google Chrome.app" ]]; then
    dockutil --add "/Applications/Google Chrome.app" /Users/david_hayter/Library/Preferences/com.apple.dock.plist
fi

and we can even make that a tad more clever with simply this:

[[ -d "/Applications/Google Chrome.app" ]] && dockutil --add "/Applications/Google Chrome.app" /Users/david_hayter/Library/Preferences/com.apple.dock.plist

P.S. for simple drag installs and ESPECIALLY things like dockutil (1 small file), Composer's "Monitor Filesystem Changes" package type works wonders and would save you a TON of time.

P.P.S. check this out it is awesome!! :D

http://mywiki.wooledge.org/BashGuide/

jacob_salmela
Contributor II

I implemented most of the changes you suggested--thanks!

However, how do you propose going about adding the spacer-tile via dockutil since it is not really an application?