views:

94

answers:

1

I tried to run equivalent of "TextMate foo.txt" using 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.

+2  A: 

Most apps don't use command line parameters. If you want to open a particular file with a particular app, use -[NSWorkspace openFile:withApplication:].

JWWalker
@JWWalker : I agree, normally apps don't use parameters. But, I need to open 'the app that I make' from Safari with parameters. I just guess launchApplicationAtURL would be the one that I need, but I can't make it work to pass the parameters.
prosseek
What do you mean "the app that I make"? Your example used TextMate, so does TextMate look for command line parameters? And what exactly did you mean by saying that it "doesn't seem to work"?
JWWalker