HELP writing recently installed applications to dock script

I am curious if anyone could shed some light on how to create a script that when you run it, it will add the most recently installed (one week) applications to the dock. When I say that, I don’t mean just adding recent applications to a stack. I am needing this because I am making one giant frankenstein script that sets up my customers brand new computers when they buy them from us. This would add any software that our team installed to the dock. I have a very basic knowledge on applescript and don’t even know where to start on this one. Any help is much appreciated.

After some searching, I’m surprised to say it’s not very easy to add something to the dock with AppleScript. A better approach might be this:

  1. Set up the dock the way you want it (apps, size, etc.)
  2. Go to the Preferences folder, located in the User’s Library folder.
  3. Find the file, which contains all the dock preferences.
  4. If you copy this file to the same folder on another Mac, the dock should be set up the way you want it.

In a previous version of this script that I’m working on, that is exactly what I did. The reason why I’m wanting to change it to where it just adds the most recent applications to the dock is because sometimes we don’t always install the same applications every time. The way we had the dock preference file set up before was with iWork and MS Office in it because those are the two most common applications that we install. However, on the occasion where the customer only wants iWork and then the Adobe CS4 suite installed too, the .plist file idea does me no good because we have to go back in and add all of the other software to the dock manually. My goal for this script (as a whole) is to be able to just run the script and then shut down the computer after its done. Thanks for the suggestion though. I really appreciate the research. Any other ideas?

I wasn’t sure how much this would help, but a user here posted a code from It will display a file dialog to choose an app to add to the dock. However, I’m not quite sure how I could edit this to do the most recent apps. I’d have to do some experimenting.

Anyway, here’s the code:

my add_item_to_dock(choose file of type {"APPL"} with prompt "Choose an application to add to the Dock:")

on add_item_to_dock(item_path)
		get item_path as alias -- you need a POSIX path so this coerces the path in case it's an HFS path, alias, file ref, etc.
		set item_path to POSIX path of item_path
	end try
		tell application "Dock" to quit
	end try
	do shell script "defaults write persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
		tell application "Dock" to activate
	end try
end add_item_to_dock

I have found that script and it does work but I am wanting to make this script to be as automated as possible. I don’t want to have to go through and choose all of the different applications that were installed. Also the problem with this is one that I have found is, say we install an Adobe CS suite for the customer. The way Adobe installs suite in the applications folder is it actually puts the app in a subfolder. With this script you are only able to select applications in one folder at a time. You can’t step into the a folder called Adobe Photoshop to select the actually applications and then step out of that same folder and select a different application. Any other ideas? Thanks so much for helping me figure this out by the way.

Model: iMac 20" 2.66 Intel Core 2 Duo
AppleScript: 2.3
Browser: Safari 4.0.3
Operating System: Mac OS X (10.6)