"Open With" starts application with empty commandLine

I’ve got an application that I’ve associated with a file type

When I have an instance of the application running and then double click a document of the associated type, everything works correctly, I get anotherInstanceStarted with the file path as commandLine.

However, if the application isn’t running and I try to start it using either the “Open With” option (on a Mac) or double clicking it, the application is opened correctly but the command line is empty and the anotherInstanceStarted function is never called.

I can’t tell if I’ve missed something that the Projucer does, but it works as intended with the anotherInstanceStarted function being called correctly.

Has anyone got any experience with this?
Is there something I’ve overlooked in the Projucer that makes it work?

Hi @andyb91. Can you post an example of this? If you open a file with your application the commandLine argument of the initialise() function may well be empty but anotherInstanceStarted() should be called after the application has been initialised with the file path of the document that you opened as the argument. Have you tried debugging your app to make sure that anotherInstanceStarted() is definitely not being called?


Hey Ed, cheers for getting back to me

I can provide an example project, but my test application, which has the same behaviour, is a simple JUCE GUI application from the Projucer. I’ve also added the file type association in the Mac OS X build target.
I’ve put an AlertWindow in the anotherInstanceStarted function, that simply displays the commandLine variable

This AlertWindow doesn’t show when using Open With, it is fine if its already running or you provide the file path as a command line argument in the Xcode scheme, everything works as expected.

I’ll have a better look at the Projucer stuff, try and get a better idea
It might be some weirdness related to the JUCE_HANDLE_MULTIPLE_INSTANCES flag, as the Projucer is manually calling sendCommandLineToPreexistingInstance

I’ll have a play around see what I can do
If you’ve got any ideas though, fire away


@andyb91 Not sure what else to suggest I’m afraid, I guess it could be some weirdness with the file association. The way I tested this was with a TextEditor in my main component which displays the command line arguments passed to the application. I added the “txt” file extension to the “Document file extensions” field of the Xcode target in the Projucer and just tried opening text files with the application. I’ve attached the Main.cpp and MainComponent.h files for my test if you want to try them on your machine.


Main.cpp (4.2 KB)
MainComponent.h (1.4 KB)

…just wondering, it sounds to me exactly as I would expect it:

These are two different callbacks, and I think that’s intentionally…

Thanks a lot for this @ed95
Oddly it worked perfectly, so I’ve clearly messed something up on my end

Thanks for your help

1 Like