Manage User Docks from the Terminal

A 2 minute read, Posted by Mark Myers on Sun, Dec 21, 2014
In MacOS, DevOps
Tags macos, automate, devops

When managing school machines there are a lot of times were you want to have a certain set of apps in the Dock on a Mac. For example you have may have a cart of MacBooks that are used as a mobile lab that should all look the same to the user.

You might be surprised how many people think there might be something wrong with the Mac because it doesn’t have the same Dock as the one they used previously. Also kids will be kids and like to mess around.

Enter dockutil (Installer Pkg), a command line utility written in Python. The installer puts the utility in the /usr/local/bin directory, which is already in your path environment. After install open up the terminal and run:

/~$ dockutil -h
usage:     dockutil -h
usage:     dockutil --add <path to item> | <url> [--label <label>] [ folder_options ] [ position_options ] [ plist_location_specification ] [--no-restart]
usage:     dockutil --remove <dock item label> | all [ plist_location_specification ] [--no-restart]
usage:     dockutil --move <dock item label>  position_options [ plist_location_specification ]
usage:     dockutil --find <dock item label> [ plist_location_specification ]
usage:     dockutil --list [ plist_location_specification ]
usage:     dockutil --version


On our cart laptops we have LaunchAgent run this bash script:



$DOCKUTIL --remove all
$DOCKUTIL --add '/Applications/Google' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/' --no-restart
$DOCKUTIL --add '/Applications/Managed Software' --no-restart
$DOCKUTIL --add '/Applications' --no-restart
$DOCKUTIL --add '~/Downloads'

exit 0

What’s going on here?!?

The $DOCKUTIL --remove all removes everything in the Dock which you might have guessed. $DOCKUTIL --add '/Applications/Google adds the Google Chrome web browser, but the added --no-restart doesn’t restart the Dock meaning we have more to do. The default action is to restart the Dock after you make a change, by passing in the --no-restart it surpresses the OSes urge to restart it. Note that the of the script we ad the Downloads folder as dockutil is able to differentiate the difference of an app and a folder.

Hopefully the dockutil becomes a good utility for you to manage a users Dock.