mac os x file association - missing filename in commandline

For Apple specific issues

mac os x file association - missing filename in commandline

Postby chkn » Wed Oct 27, 2010 6:02 pm

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().
chkn
JUCE UberWeenie
 
Posts: 861
Joined: Thu Mar 08, 2007 6:17 pm

Re: mac os x file association - missing filename in commandline

Postby jules » Wed Oct 27, 2010 10:16 pm

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.
User avatar
jules
Fearless Leader
 
Posts: 17189
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: mac os x file association - missing filename in commandline

Postby chkn » Thu Oct 28, 2010 8:18 am

Code: Select all
It should pass you the filename in anotherInstanceStarted()

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.
chkn
JUCE UberWeenie
 
Posts: 861
Joined: Thu Mar 08, 2007 6:17 pm

Re: mac os x file association - missing filename in commandline

Postby jules » Thu Oct 28, 2010 10:31 am

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

Maybe this thread is helpful:
viewtopic.php?f=4&t=6020
User avatar
jules
Fearless Leader
 
Posts: 17189
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: mac os x file association - missing filename in commandline

Postby chkn » Thu Oct 28, 2010 12:41 pm

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: Select all
    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;
};
chkn
JUCE UberWeenie
 
Posts: 861
Joined: Thu Mar 08, 2007 6:17 pm

Re: mac os x file association - missing filename in commandline

Postby jules » Thu Oct 28, 2010 1:26 pm

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.
User avatar
jules
Fearless Leader
 
Posts: 17189
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: mac os x file association - missing filename in commandline

Postby chkn » Thu Oct 28, 2010 1:40 pm

no problem, my solution works good.
chkn
JUCE UberWeenie
 
Posts: 861
Joined: Thu Mar 08, 2007 6:17 pm


Return to MacOSX and iOS

Who is online

Users browsing this forum: No registered users and 2 guests