views:

464

answers:

3

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?

+2  A: 

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

tedge
I have set up my CFBundleDocumentTypes array properly, and wrote the method, but The dock icon will simply not accept my file.
Tristan Seifert
Tristian Seifert: One possible cause of that problem is that you specified a UTI in your plist, but it was the wrong one: http://boredzo.org/blog/archives/2007-07-23/how-to-make-your-apps-dock-tile-highlight You also should make sure to import any UTIs you mention in the plist: http://developer.apple.com/mac/library/documentation/FileManagement/Conceptual/understanding_utis/
Peter Hosey
After reading these two documents, I still do not quite understand how to add UTI's to my existing PList. Here is a small section of my Info.plist: <dict> <key>CFBundleTypeIconFile</key> <string>Draft.icns</string> <key>CFBundleTypeExtensions</key> <array> <string>podraft</string> </array> <key>CFBundleTypeName</key> <string>Post Office Draft</string> </dict>What would I have to add to this definition so the dock will accept the File?
Tristan Seifert
Finder opens the Files with my app automatically, but the dock still won't after I deleted the build folder and re-built.
Tristan Seifert
A: 

If you're actually making a document-based app, setting it up to give you the path will have you doing far more work than you need to. Simply use the document-based application template. The document controller will create an instance of the right class for you; you need only write that class.

An application you create this way will handle file drops (by opening them as documents) for free.

Peter Hosey
It is not a document based App, It is an Email reader, and I would like to be able to drag drafts, mailboxes, etc. onto my dock icon.
Tristan Seifert
A: 

Select your application in the target group of the side pane and use get info. Then in the new window select the properties tab to add a new document type. Name it "Folder" for convenience and the OS Types needs to be "fold"; the store type and role you can leave as is.

Conor