Application opened with user document

Hi Jules -

How do you find out whether an application was started because a user has double-clicked a file? Equivalently, on OS X how do you get the command line args given to the open command? This info seems not to be given to the JUCEApplication::initialize() method’s commandLine arg.

However, that info is given to the commandLine arg of JUCEApplication::anotherInstanceStarted. So, I can only determine the file the user clicked on when an instance of my application is already running. The first instance that starts cannot find out about its command line args.

Is this intentional? Am I missing something? Thanks!

Yes, it should be there in the commandLine arg of initialise()…

Yeah, something is fishy then. I don’t think I’m missing anything I should know about. Here’s the context:

  1. In Projucer, the “Document file extensions” field reads e.g. .xyz
  2. With no application instance running, I do open from the command line, or double click that file in Finder.
  3. Program stars, but the commandLine arg to initialize is an empty string.
  4. Do the same thing again with the app still running: anotherInstanceStarted is invoked, now with as the sole argument.

My application is being launched by Finder from its location in the Builds directory. Could that have something to do with it? I don’t have any other ideas right now…

Hmm. I can click on a projucer file and it opens in the projucer… That’s the same thing. I suspect you’re making a mistake in your code somewhere.

Interesting. Indeed your build of the Projucer works as expected. However, if I build Projucer.xcodeproj on my machine I get the same behavior. Sounds like an issue with my Xcode environment then.

Ok, I think I have this sorted out. I don’t ever see the clicked file given to initialise(), I always get it in anotherInstanceStarted(). If the app is not already running, and is invoked by clicking on a file then I get calls to both functions, one after the other.

I presume that’s the intended behavior.