4

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.

prosseek
  • 182,215
  • 215
  • 566
  • 871

1 Answers1

3

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
  • 22,385
  • 6
  • 55
  • 76
  • 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 Jul 26 '10 at 04:57
  • 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 Jul 26 '10 at 05:08