How to use NSWorkspace launchApplicationAtURL?
I tried to run equivalent of "TextMate foo.txt" us开发者_如何学Going launchApplicationAtURL. The name of binary is "TextMate", and I have one parameter.
I tried the following code, but it doesn't seem to work.
// find the textmate
NSURL * bURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.macromates.textmate"];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
// find the parameter
NSString * f = @"foo.txt";
NSArray * myArray2 = [NSArray arrayWithObjects:f,nil];
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setObject:myArray2 forKey:NSWorkspaceLaunchConfigurationArguments];
[ws launchApplicationAtURL:bURL options:NSWorkspaceLaunchDefault configuration:dict error:nil];
What's wrong with this?
Added
I checked this code actually works, I got something wrong with how 'TextMate.app' deals with the parameters.
Most apps don't use command line parameters. If you want to open a particular file with a particular app, use -[NSWorkspace openFile:withApplication:]
.
精彩评论