开发者

Create simple cocoa application wrapper

I have an application I want to bundle (with some additional files) together inside a wrapper application.

Literally the only thing I want to do is have the wrapper application launch a resource file (i.e. as if I'd typed:

/path/to/Resources/Bundled.app/Cont开发者_如何学Cents/MacOS/executable

into the terminal.

Make sense? I thought this should be simple, but I caouldn't find a simple way to do this-- my cocoa programming is limited, to say the least.

Thanks in advance!


One way, if the wrapped “application” is just a shell script or something, is Platypus.

If it's an actual application (.app bundle), why does app A do nothing but launch app B? Why have app A at all?


Your outer program can use NSBundle to locate the inner program within the outer program's bundle.

To run the inner program: If it's an application, use Launch Services or NSWorkspace; if it's a command-line tool, use NSTask.


I have a blog post up on this: Turn any shell script into a double-clickable app. The entry mentions "start with an empty app bundle"... which you can get by using the Pashua tool mentioned, if I remember correctly...


Just for the sake of posterity (and if it helps anyone else, here is the full code I used (inside the AppDelegate.m file):

NSString *appName = @"";
NSString *bundledApp = [[NSBundle bundleWithPath:[[NSBundle
                                                           mainBundle] pathForResource:appName ofType:@"app"]]
                          bundlePath];
NSWorkspace *launchApp = [[NSWorkspace alloc] init];
NSLog(@"Launching %s", bundledApp);
[launchApp launchApplication:bundledApp];
[launchApp release];

// Make Launcher terminate (if it serves no other purpose)
[NSApp terminate:nil];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜