Can an alias be added to the dock via the command line?

I found this article but it handles the GUI solution.

I would like to automate the setup of a new machine, and do that I've created Dropbox shares of a number of my common configurations. (I could use a github repo, too) Other sites have discussed automating pref configs.

I'd like a bash / terminal command to create an alias in the dock. I presume that the dock is a folder of aliases located somewhere in ~/Library but I can't find it.

Is there any AppleScript solution?


edit: it seems that there is a file, ~/Library/Preferences/com.apple.dock.plist that contains the references.

A Japanese engineer discusses an way to do this C. 2009 (which no longer works).
Another script was designed to add folders to the 'others' area of the Dock – which is alos dated. The latter, however, along with the new format for the Dock plist, and some dict manipulation tips, gives more clues to creating a modern script.


Definitely scriptable with terminal commands.

/usr/libexec/PlistBuddy -c "Print" ~/Library/Preferences/com.apple.dock.plist

Shows you the actual configuration for the dock.

Within the above file you need to modify the "persistent-others" array if you want to create a "file" alias.

This is done the following way:

/usr/libexec/PlistBuddy -c "add:persistent-others:0 dict" ~/Library/Preferences/com.apple.dock.plist

If you want an application alias you will need to modify the "persistent-apps" array.

Once you make the changes and you are testing you need to do:

killall dock

to refresh the dock.