2

i'm searching for a way to open my other application with parameters and found a very good post here, but on my developer machine I have like 10 test/brach/release versions of my application and only one current stable version in /Application folder.

Both this code:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];

NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:@"My Application"]];
NSURL *url = [workspace URLForApplicationWithBundleIdentifier:@"it.my_company.my_application"];

points to the wrong test/branch/release version. How do I find the URL of my application in /Application folder or at least URL at same level as my current running application?

Community
  • 1
  • 1
Shebuka
  • 3,148
  • 1
  • 26
  • 43

2 Answers2

1

You could use the NSTask messages: setLaunchPath or launchedTaskWithLaunchPath to supply an explicit path to your other application.

Something like:

NSArray *args = [NSArray arrayWithObjects:nil];
[NSTask launchedTaskWithLaunchPath:@"/Applications/My Application.app/Contents/MacOS/My Application" arguments:args];
pb2q
  • 58,613
  • 19
  • 146
  • 147
  • I'v considered it, but it's a manual path writing... I was looking for altering the path search order. – Shebuka Jul 23 '12 at 14:24
1

This is what i'v came out to use:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];

NSString *appPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
appPath = [appPath stringByAppendingPathComponent:@"MyApp.app"];

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath])
    appPath = @"/Applications/MyApp.app";

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath])
    appPath = [workspace fullPathForApplication:@"MyApp"];

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath]) {
    return NO;
}
else {
    // found it in some place, now can launch.
Shebuka
  • 3,148
  • 1
  • 26
  • 43