skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. Referencing my comments above, one can open multiple files in an application using the NSWorkspace method openURLs: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 pass NULL to the configuration: parameter. Likewise, there are a multitude of NSWorkspaceLaunchOptions available, but if none of those are desired, one can pass 0 to the options: parameter:

    NSURL *appURL = [NSURL fileURLWithPath:@"file:///path/to/application.app"];
    NSArray *fileURLs = [NSArray arrayWithObjects:[NSURL fileURLWithPath:@"file:///path/to/file1"],
                                                  [NSURL fileURLWithPath:@"file:///path/to/file2"],
                                                  nil];
    NSError *err = nil;
    BOOL success = [[NSWorkspace sharedWorkspace] openURLs:fileURLs withApplicationAtURL:appURL 
                                                  options:0 configuration:NULL error:&err];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search