I have a NPAPI plugin for MAC that downloads and runs an Application from server.
When i use NSTask to open up the application. The application does not come to front.
NSBundle *bundle = [NSBundle bundleWithPath:AppPath];
NSString *path = [bundle executablePath];
NSTask *task = [[NSTask alloc] init];
NSArray *arguments;
arguments = [NSArray arrayWithObjects:AppParam,nil];
[task setLaunchPath:path];
[task setArguments:arguments];
[task launch];
I searched for the solution and came up with the code
int pid = [task processIdentifier];
ProcessSerialNumber psn;
GetProcessForPID(pid, &psn);
SetFrontProcess(&psn);
but this code does not bring the application to front then i tried the following code.
NSRunningApplication *runapp = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
[runapp activateWithOptions:0];
This did not yield the desired result.
After some searches I came across posts that suggested the use of NSWorkspace to launch and activate the application. I came up with the code.
[workspace
launchApplicationAtURL:[bundle bundleURL]
options:NSWorkspaceLaunchNewInstance
configuration:[NSDictionary
dictionaryWithObject:arguments
forKey:NSWorkspaceLaunchConfigurationArguments]
error:error];
This works all OK BUT not under one situation. When the application is downloaded and executed FIRST TIME by the NSworkspace command MAC prompts with a dialog " is an application downloaded from the internet. Are you sure you want to open it".
If Pressed OK the application does launch but does not come to front.
This dialog only appears if application is launch through NSWorkspace. Launching with NSTask, MAC does not prompt with the dialog before executing.
Could not find a solution that would go through the problem. I am OK with a confirmation dialog with NSWorkspace but can anyone suggest something that would still bring an application to front after clicking OK.
I also tried using.
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[[NSWorkspace sharedWorkspace] activeApplication];
Any help in this would be appreciated. Thanks in advance.
Regards,
LazyCoder7.