Some applications, like Photoshop, allow users to drag a picture from a web browser, or drag a file from the filesystem, onto the application's icon in the dock. Doing this opens the file in that application.

How is this done? I'd like to use Cocoa and Objective-C, but I'm interested in any solutions in any languages.

I don't think that you can use Cocoa and C#. I only know of Cocoa bindings from Ruby, Python, and Objective-C (with Objective-C being the best supported, from my understanding). While you can write OS X apps using C# with Mono, I don't think that you can use Cocoa from C#.
–
AndyFeb 1 '09 at 16:35

of your delegate object, in case it implements any such method. In case the content is not really a file (e.g. if the user just selects text in an application and drags it onto your dock icon), the delegate method

Basically you can just create any object of any kind (e.g. a simple one that just inherits of NSObject), define the two methods of above within the object and then anywhere in your start up code of the app you do

And that's it. As soon as a file or some other content is dropped onto the dock icon, the appropriate method is called and must handle that request. BTW the same methods are called if your application associates with a file type (e.g. .myFileType) and the user double clicks a file with that extension in the Finder.

What really happens behind the scenes is that Launch Services sends your
application an "open documents" ('odoc') Apple Event. NSApplication by default registers a handle for this event and forwards the request by calling the appropriate delegate method. You can also directly listen to this Apple Event I guess, but why would you? Dealing with Apple Events directly is awkward. When your application is not Cocoa, but Carbon (plain-C), you may have to directly process the Apple Event (I'm not familiar with Carbon), but in Cocoa Apple already catches the most important Apple Events for you and converts them into delegate calls or notifications your application can listen to.

If your application is document-based and you filled out the necessary keys in your Info.plist correctly, then it Just Works. When the user drags a file to your application's Dock tile, Dock will highlight your app on the tile if the file is of a type you signed up for, and if the user drops the file there, NSDocumentController will instantiate one of your document classes for the file. If the file is not of a type you signed up for, both will ignore it.

So, is your app document-based? If so, is the file one of a type you signed up for?