I would like to open Photoshop app with some arguments via launchApplicationAtURL. Photoshop is opened but the image that I specified in the parameter list is not opened.
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSString *urlString = [NSString stringWithUTF8String:imageEditorPath.GetPlatformString().c_str()];
NSURL *url = [[NSURL alloc] initFileURLWithPath:urlString];
//Handle url==nil
NSError *error = nil;
NSArray *arguments = [NSArray arrayWithObjects:@"/Users/admin/q/177381.png", nil];
[workspace launchApplicationAtURL:url options:0 configuration: [NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];
2
Answers
CJKs answer is right: [[NSWorkspace sharedWorkspace] openURLs:fileURLs withApplicationAtURL:appURL options:0 configuration:0 error:&err]; where fileURLs is your array of files to be opened, and appURL points to the application. – CJK
CJK - Please send it as answer.
Referencing my comments above, one can open multiple files in an application using the
NSWorkspace
methodopenURLs:withApplicationAtURL:options:configuration:error:
. If you don’t need to send any arguments to the application, or set environment variables for the app, then one can simply passNULL
to theconfiguration:
parameter. Likewise, there are a multitude ofNSWorkspaceLaunchOptions
available, but if none of those are desired, one can pass0
to theoptions:
parameter: