Hi Jules,
I had an application which used juce 1.39 and I had couple of custom files. Double clicking on these custom files used to launch my application. Back then when a custom file was double clicked this method was called “virtual void initialise (const String &commandLineParameters)” where commandLineParameters would be the path of the file clicked.
I have ported my application to use juce 1.50(this happens on juce 1.46 too), now when I double click my custom file, I don’t get the path of my custom file as command line argument. I get a weird value. An example for that is "-psn_0_159783 "(picked it up from the console application). This also happens with “void JuicerApp::anotherInstanceStarted (const juce::String& commandLine)”.
The weird part of this problem, If am running my application using Xcode and I double click on my custom file, the commandLine contains the file path.
Just an update on this, I got it working, I implemented, “JUCEApplication::anotherInstanceStarted (const String& commandLine)” and handled the custom file double click here.
Even if my application isn’t running when the custom file is double clicked, it calls “JUCEApplication::anotherInstanceStarted (const String& commandLine)”, shouldn’t it be calling “JUCEApplication::initialise (const String &commandLineParameters)”.
I had an application which used juce 1.39 and I had couple of custom files. Double clicking on these custom files used to launch and load that custom file in my application.
I have ported my application to use juce 1.50(this happens on juce 1.46 too), now when I double click my custom file, I don’t get the path of my custom file as command line argument. I get a weird value. An example for that is "-psn_0_159783 "(picked it up from the console application). This also happens with “void JuicerApp::initialise (const juce::String& cmd)”. Then I debugged the application and found when my application is running, dragging or double clicking on custom file works fine means it loads custom file in app because JuceAppDelegate calls
- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
{
return redirector->openFiles (filenames);
}
then redirector calls:
virtual void openFiles (NSArray* filenames)
{
StringArray files;
for (unsigned int i = 0; i < [filenames count]; ++i)
files.add (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
// AlertWindow::showNativeDialogBox("To check Path in openFiles at top ", files.joinIntoString (T(" ")).toUTF8(), true); just for checking the custom filepath.
if (files.size() > 0 && JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
}
}
but when my app is not running and I am just double clicking on custom file or dragging on my app on doc it’s launching my app but not loading the custom file .It is showing command line path “-psn_0_159783” in “void JuicerApp::initialise (const juce::String& cmd)” method and not calling above methods.
I have gone through the command line related all topic’s but did not find solution. Any help would be appreciated.
I am just digging in the same problem and observed one more thing.
it happens( command line argument “-p_45677778”) when your application launches model or model less window before launching of application’s main window ( I checked it by showing a showNativeDialogBox) otherwise it’s passing proper
string and loading custom file.
While debugging I noticed the call stack…
#0 0x00379b60 in JuicerApp::anotherInstanceStarted at JAJuicerApp.cpp:477
#1 0x02625b4b in juce::AppDelegateRedirector::openFiles at juce_mac_MessageManager.mm:90
#2 0x0261c571 in -[JuceAppDelegate_1_50_3 application:openFiles:] at juce_mac_MessageManager.mm:201
#3 0x90665488 in -[NSApplication _doOpenFiles:]
#4 0x906653e1 in -[NSApplication(NSAppleEventHandling) _handleAEOpenDocuments:]
#5 0x903870db in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:]
#6 0x9258fa9f in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:]
#7 0x9258f7af in _NSAppleEventManagerGenericHandler
#8 0x914e6648 in aeDispatchAppleEvent
#9 0x914e657e in dispatchEventAndSendReply
#10 0x914e6425 in aeProcessAppleEvent
#11 0x95f9c981 in AEProcessAppleEvent
#12 0x903848e9 in _DPSNextEvent
#13 0x90383f88 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#14 0x9037cf9f in -[NSApplication run]
#15 0x0261c805 in juce::MessageManager::runDispatchLoop at juce_mac_MessageManager.mm:263
#16 0x023e4e9e in juce::JUCEApplication::main at juce_Application.cpp:205
#17 0x023e50d1 in juce::JUCEApplication::main at juce_Application.cpp:285
#18 0x0037a2a3 in main at JAJuicerApp.cpp:625
#19 0x00002e52 in _start
#20 0x00002d79 in start
I am little bit confused . is “- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames” being called by NSApp ???.
still i am not able to fix the prob. waiting for a reply.
It’s some kind of a process serial number, but I’m not sure what you’re supposed to do with it… Couldn’t find any info online - anyone got a clue about this?
Adding to previous post, I have fixed command line issue in my application . I observed while debugging that command line argument( i.e. argv[1]) is not properly coming
( i.e. like “-psn_0_1594432”) in “anotherInstanceStarted()” while clicking on any custom file to launch the app and load the file because application is launching modelless windows before app main window and not loading the file. so just I have started a timer in “initialise()” method for 1 sec so that " _command = cmd " will be set properly and
then load the modelless window.
I have written following code.
void JuicerApp::initialise (const juce::String& cmd)
{
_command = cmd;
#ifdef JUCE_MAC
/* This will set initialisation true, and starts a timer(e.g new thread) for 1 sec that will do the initialisation
and first thread will call anotherInstance started there _command will be set with proper value. */
_bIsAppInitialisedFirstTime = true;
startTimer(1000);
#else
initialiseWithModellessWindow(_command);
#endif
}
void JuicerApp::timerCallback () {
stopTimer();
#ifdef JUCE_MAC
/* First time only in 30 milisec controll will come here from anotherInstanceStarted() and initialise the app and sets _bIsAppInitialisedFirstTime
to false so, now in second call only else part will be called with earlier set _command to load batch */
if(_bIsAppInitialisedFirstTime == true)
initialiseWithModellessWindow(_command);
else {
MY_AnotherInstanceStarted(_command);
}
_bIsAppInitialisedFirstTime = false;
#endif
}
void JuicerApp::anotherInstanceStarted (const juce::String& cmd)
{
_command = cmd;
#ifdef JUCE_MAC
startTimer(30);
#else
MY_AnotherInstanceStarted(_command);
#endif
}
I know Jules won’t accept it but i created all four type of App, Juce, Cocoa, Carbon C and Carbon C++ and got the same result in main(int argc, char* argv[])
argv[1] is always something like “-psn_0_1594432” . Please if anybody is finds a better solution do post in.
Just trying to look at this, but I can’t replicate it at all. The filenames seem to work fine for me (testing in the new jucer build, which can now open .jucer files).
I can’t understand what your solution is trying to fix… Do you mean that your app is blocking the event thread for a few seconds when it launches, and that’s what’s somehow preventing the filenames getting through? I tried simulating that, but it still worked for me. Showing a window, whether modal or modeless (and it’s not clear which of those words you actually mean when you say “modelless”!) should make no difference at all to the delivery of the openFiles event or the filenames it contains…
Actually not. I’m using the March 31 version. I (rather rapidly) looked at the git log and it seemed to me that there was no related modification.
After my post I’ve also found your last reply to this post http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=4323 and that looks like a definitive answer.
Now I have this problem, which does not seem to be related to JUCE: if my application is already running, double clicking on a file in the finder opens it correctly through anotherInstanceStarted(). But if the application is not running, it is not launched. My other applications work flawlessly and their Info.plist are similar. Any suggestions?
That does sound pretty strange, but must be plist related… How the OS keeps track of which binary it should launch is a bit of a mystery anyway, I’ve never been quite clear about what it does.