Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Apple Software > Mac Programming
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 14, 2009, 05:17 PM   #1
petron
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
What method is called when double click launch an App

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:

Quote:
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
petron is offline   Reply With Quote
Old Oct 14, 2009, 05:38 PM   #2
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: 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).
__________________
Search MacRumors with:MRoogle
GorillaPaws is online now   Reply With Quote
Old Oct 14, 2009, 07:27 PM   #3
kainjow
Demi-God (Moderator)
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   Reply With Quote
Old Oct 15, 2009, 02:14 AM   #4
petron
Thread Starter
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
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
petron is offline   Reply With Quote
Old Oct 15, 2009, 02:25 AM   #5
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: Richmond, VA
Quote:
Originally Posted by petron View Post
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.
__________________
Search MacRumors with:MRoogle
GorillaPaws is online now   Reply With Quote
Old Oct 15, 2009, 04:09 PM   #6
petron
Thread Starter
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
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
petron is offline   Reply With Quote
Old Oct 16, 2009, 10:44 AM   #7
rossipoo
macrumors member
 
Join Date: Jun 2009
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/libra...Reference.html

http://developer.apple.com/mac/libra...TypePList.html

Last edited by kainjow : Oct 16, 2009 at 04:25 PM. Reason: merged posts
rossipoo is offline   Reply With Quote
Old Oct 16, 2009, 01:23 PM   #8
petron
Thread Starter
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
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 is offline   Reply With Quote
Old Oct 16, 2009, 04:26 PM   #9
kainjow
Demi-God (Moderator)
 
kainjow's Avatar
 
Join Date: Jun 2000
Have you looked at the application:openFiles: method?
kainjow is offline   Reply With Quote
Old Oct 17, 2009, 05:16 PM   #10
petron
Thread Starter
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
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 is offline   Reply With Quote
Old Oct 17, 2009, 05:59 PM   #11
petron
Thread Starter
macrumors member
 
Join Date: May 2009
Location: Malmo, Sweden
Send a message via ICQ to petron
Hi, Kainjow.

You are genie . 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
petron is offline   Reply With Quote

Reply

Mac Forums > Apple Software > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:16 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 2002-2010, MacRumors.com, LLC