Mac os x file association - missing filename in commandline


#1

I’ve associated a file-extension with my application (in info.plist).
When opening a document from the finder i get only something like “-psn_0_123456” in the commandLine (in initialise()).
If the application is running and i click on the document i get the correct filename in anotherInstanceStarted().


#2

It’s a process serial number, though I’m not sure what you’re supposed to do with it. It should pass you the filename in anotherInstanceStarted() anyway, though, so you can ignore the -psn thing.


#3
no, it does not (when you open a document from the finder, and the application is not running yet.)
The new jucer (3.0) , behaves the same. It does not open the file you clicked, it just checks for the character "-" in the commandLine and open the documents which were last time opened, but not that one which you clicked.

no, it does not (when you open a document from the finder, and the application is not running yet.)
The new jucer (3.0) , behaves the same. It does not open the file you clicked, it just checks for the character “-” in the commandLine and open the documents which were last time opened, but not that one which you clicked.


#4

erm… yes it does! I just tried the jucer - it works fine.

Maybe this thread is helpful:
http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=6020


#5

ahh, i see (had a splash screen, added a alertBox to the Jucer to see whats going on, and so we have the same behaviour…)

But if we you use the AsyncUpdater-Method, we have also complete different behaviour on Windows (which uses the Initialise commandLine), also we have to care, because anotherInstanceStarted() on Mac is called before the async initialisation.

something like this:

[code]
void initialise (const String& commandLine)
{
initialiseCommandLine=commandLine;
triggerAsyncUpdate();
}

void handleAsyncUpdate()
{
   	SplashScreen* splash = new MainSplash();
	splash->show(ApplicationName,470,200,1000,true,false);
	
    // just create the main window...
	mainWindow = new MyWindow();
	
	// do init stuff etc...

	String fileNameCommandLine=extractFileNameFromCommandLine(initialiseCommandLine);
	
	if (fileNameToOpenAfterInit.isNotEmpty())
	{
		mainWindow->openFile(fileNameToOpenAfterInit);
		fileNameToOpenAfterInit="";
	} else
	{
		if (fileNameCommandLine.isNotEmpty())
		{
			mainWindow->openFile(fileNameCommandLine);
		}; 
	}

};

void anotherInstanceStarted (const String& commandLine)
{
	String fileName=extractFileNameFromCommandLine(commandLine);

	if (fileName.isNotEmpty())
	{
		if (mainWindow!=0)
		{
			mainWindow->openFile(fileName);
		} else
		{
			// Application not intialised yet!
			fileNameToOpenAfterInit=fileName;
		}
	}
}

    
bool moreThanOneInstanceAllowed()
{
    return false;
}

private:

String fileNameToOpenAfterInit;
String initialiseCommandLine;

};[/code]


#6

Well… I don’t really know what I could do about that. The filename simply isn’t available on the mac until the OS chooses to call anotherInstanceStarted(), and we have no control over when that might happen.


#7

no problem, my solution works good.