Tiny Deathstars of Foulness

Using Mac OS X, one of the most trivial things (provided you have permission) is to add an object to the dock. Applications go on the left side of the dock and folders/documents/stacks go on the right. From the command line it isn’t quite as trivial but not that complicated either. To do so from the command line, you can write directly into the for a user. To do so, we’re going to use the defaults command and we’re going to look at adding an application first:
defaults write persistent-apps -array-add ‘<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft Office 2008/Microsoft Word</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>’
You can also add a custom title for the object that you are adding by using the file-label key and providing a string with the content that you want the label to have. You can also add a folder or file to the dock using a similar command:
defaults write persistent-apps -array-add “<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users</string><key>_CFURLStringType</key><integer>0</integer></dict><key>file-label</key><string>UsersDirectory</string><key>file-type</key><integer>18</integer></dict><key>tile-type</key><string>directory-tile</string></dict>”
You can also write  an object using a variable, or another command when wrapped with “. For example, if we wanted to put a link to the specific users directory rather than the /Users directory we would use the following:
defaults write persistent-apps -array-add “<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users/`whoami`</string><key>_CFURLStringType</key><integer>0</integer></dict><key>file-label</key><string>MyHome</string><key>file-type</key><integer>18</integer></dict><key>tile-type</key><string>directory-tile</string></dict>”
There are several uses for this. For example, you can link to certain folders that allow you to access recently changed content. Provided you have mounted a network share you can also add a network directory, similar to what happens when you add your Network Home in managed preferences. But this gets the process started and from here it’s just figuring out your specific logic. Once you have added an item into the Dock you’ll then need to restart it:
killall Dock
You should then see your Dock item. It is worth noting that if the location does not exist then you will need to create it and so you might script some logic as such. Also, if you create the location after creating the item then you will need to restart the Dock again.

August 2nd, 2010

Posted In: Mac OS X, Mass Deployment

Tags: , , , , , , , , ,