Dropping Files onto Dock Icon in Cocoa

Tristan picture Tristan · Mar 22, 2010 · Viewed 9.3k times · Source

How can I drop a file(or select to open it in Finder) of a type specified in the Info.plist onto my dock icon and then calling a method with the full path of the file?

Answer

Josh Freeman picture Josh Freeman · Mar 22, 2010

If you've set up your Info.plist's CFBundleDocumentTypes array properly (either 'LSItemContentTypes' or 'CFBundleTypeExtensions'), then you just need to set up an NSApplication delegate and implement the delegate method, application:openFile:.

If you're expecting multiple files to be dropped at once, implement application:openFiles:.

For promised files (NSFilesPromisePboardType/kPasteboardTypeFileURLPromise) see Dropping promised files on to application icon in Dock.