Opening files via double-click with Cocoa

I need to have my document-based Objective-C/Cocoa application open a file upon double-clicking in the Finder. I understand how to tell Finder to use my application as default for the filetype I need. Currently, I have written the code to open files via the File..Open.. menu, but if I double click an applicable document file, my application starts, but does not load the file.

I know this has got to be a pretty basic question, but I have been unable to find any documentation or other online info out there that tells me how to do this. Thanks in advance for any help!

Mac OS X (10.4.6)

Posted on Apr 25, 2006 9:51 AM

Reply
4 replies

Apr 25, 2006 11:23 AM in response to DiscoTex

You have to add your document type as one of the types your program handles. Select your target from Xcode's Group and Files list and click the Info button. Click the Properties tab in the target's information panel. At the bottom of the panel is a list of document types. For a document-based Cocoa application, Xcode includes one document type. You can either modify that document type or add a new document type for your document file.

Mac OS X (10.4)

Apr 26, 2006 1:54 PM in response to Mark Szymczyk

Thanks for your input, Mark. However, my problem goes a little deeper than that. It appears that I have left out some quite pertinent information.

My "document types" are already set up. If I run my application, then double click a document file, the file is opened properly. However, if I launch the application by double-clicking a document file, the application launches without opening the file or loading the document nib.

How is the double-clicking of a file in Finder handled? Is it an event that is handled by the appication object? If so, maybe there is something weird going on with my responder chain...?

May 1, 2006 12:41 PM in response to Mark Szymczyk

Thanks, Mark. Your input set me on the road the the right answer.

So, in my application I have a splash screen that displays as a modal panel + a timer that tells me when to close the modal panel. It looks like the modal panel was precluding all of my application's delegate messages on launch. I fixed the problem by changing the panel from a modal to a regular panel and ordering it to the front at a level above my document view.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Opening files via double-click with Cocoa

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.