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: , , , , , , , , ,

  • nate

    there’s also this, which works well.

    or local or traditional mcx.

    or the jamf binary (if you use the casper suite for management).

  • True enough. I should have been more specific. When I wrote this I needed to use %@ for the MCX to work. It wouldn’t accept that, so I defaulted back to looking at this. I hadn’t seen the Google code project (which funny enough, I Googled this before delving into the key structure). I’m guessing they’re doing a lot more logic than this… 😉

  • paul teeter

    big fan of the dockutil app linked above. great for on the fly remote dock modifications. can send Terminal command over ARD to remote user’s machine to instantly update their dock. plus can control exact positioning of new item. plus can operate on all machine account docks in one fell swoop.

  • dave

    This will add ( Or any app – just change path to what you want ) to the dock, Make sure to run as current console user in ARD and that users are logged in

    defaults write persistent-apps -array-add “tile-datafile-data_CFURLString/Applications/”;

    to refresh dock:

    killall -HUP Dock (run as root in ARD)

  • You may also be interested in additemtodock :