Just a note about the problem of getting only the file path when a file is double clicked. This is particularly relevant if you have an application that is not NSDocument based, but can still open files.
Once you have the file associations set up as mentioned in this thread (by setting your pList corrently) then double clicking a file will call
- (BOOL)application: (NSApplication * )theApplication openFile: (NSString * )filename;
of your application delegate.
However, if double clicking that file causes your app to launch, then this function is actually called before your
- (void)applicationDidFinishLaunching: (NSNotification * )aNotification
method. So, if you have significant initialization in the applicationDidFinishLaunching you should save the filename variable into a member variable of your delegate, and process it once the initialization is complete.
- (BOOL)application: (NSApplication * )theApplication openFile: (NSString * )filename
{
// if the file opening launches us, we have not initialized pApp_G, or our controllers, etc
// so we we need to store the launch path and then load the file later.
if(!pApp_G)
{
// store it in an array (or just set an NSString)
m_openedFilesArray = [NSMutableArray arrayWithCapacity: 1];
[m_openedFilesArray addObject: filename];
}
else
{
//handle the file opening directly here
}
return TRUE;
}
Hope this helps some of you that have also had this issue.