Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Hi,
I wonder which method is called when an user click twice on an file icon in the Finder. The application I talk about is not document based.

I have an application that I use to manipulate some data base files, I associated a file type to it. I do pick up the Doc name into the App and then manipulate it. Works fine, but I would like to double click on a file, start the App and have ready to go setup.

When clicking on that file type, the main application starts up correctly but I do get an error:

The document “create_db.dbmm” could not be opened. Create DB cannot open files in the “Create DB Doc” format.

I assume that I do lack a method that handles the notification during the application start up. Frankly I do not have an idea how to find it out.

I wondered for a while about the NSApplicationDelegate, but I am not sure how it should work.

A question arise as well, Should I rewrite the Application to be a Document based one, even if I do not really need it ?

I will appreciate some help in pushing me in the right direction

/petron
 

GorillaPaws

macrumors 6502a
Oct 26, 2003
932
8
Richmond, VA
This document might be a good jumping-off point. Hopefully someone else can give you a more specific answer. I'd be interested to hear what the best practices are for this type of interaction (i.e. using Apple Events vs. NSTask to interact with the OS and other applications).
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Are you getting that message in the Finder? If so, then somehow it hasn't been registered to open with your app yet. If your Info.plist is setup properly, then you might need to Get Info your file and change the Open With field.
 

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Thanks for the link GorillaPaws, I will try to look through it.

Kainjow,
The application has been started properly, and it seems like an opening of the document failured in the App, not in the finder.
Frankly, I am not very surprised since in my App Controller for this application I do not have any method that would handle such a event/callback/delegate.
But I assume that there is a mthod that I can over write to handle the event and pick up the file into the App. But I do not know it yet.

Thanks for replies.
/piotr
 

GorillaPaws

macrumors 6502a
Oct 26, 2003
932
8
Richmond, VA
Thanks for the link GorillaPaws, I will try to look through it.

I think I misunderstood what you were trying to do. I got the impression that your app was trying to interact with data in a second app. After re-reading your post, I realized my mistake.

For certain, don't rewrite your app to be document-based if you don't need that functionality.
 

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
A short notice...

I have verified that the Warning message is generated from my application.
In the window I do see the warning sign together with the icon of my program.

So the question is still valid, which method can I override in order to catch the opening file event from the Finder.

I hope there is an answer...

/piotr
 

rossipoo

macrumors regular
Jun 7, 2009
109
0
An associated a file type seems odd for a non-document based app. Where you need to put loading code depends on what is being done in the loading code. NSApplicationDelegate has a method called applicationWillStart (you may want to double check the class documentation) which runs early in the startup process. At that point however, you can't do anything Cocoa related (creating views). For that you should probably use awakeWithNib, which runs late in the startup process, after the interface has been initialized. awakeWithNib is called for any class instance that is part of the Nib file.

NSDocument has a method called initWithURL: . The documentation says this in invoked by NSDocumentController. If your app is not document based then I don't know how this works.

http://developer.apple.com/mac/libr...ses/NSDocument_Class/Reference/Reference.html

http://developer.apple.com/mac/libr...nceptual/Documents/Concepts/DocTypePList.html
 

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Thanks Rossipoo

I will take a look at the NSApplicationDelegate.

To be honest what I need when clicking on the file is not to open the file but to get its path into the application. Thanks again

/petron
 

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Thanks Kainjow for the idea.
No I did not look at it yet. I will try it soon. Right now I did started another cocoa project. I do write a simple log converter for amateur radio.

/petron
 

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Hi, Kainjow.

You are genie :D . It works like a charm now.
The trick was to add this line in init method

Code:
[NSApp setDelegate:self];

and then I added what I needed

Code:
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
    [self setValue:filename forKey:@"sourceFile"];
    [outField setStringValue:filename];
    return YES;
}


Thanks again...I will send you soon a link to my page with the software.

/petron
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.