Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch application from application bundle

I have a helper application, which is within my main application's application bundle (in the Resources). I'm not sure how to get the path of the application from inside the bundle and launch it.

like image 955
alexyorke Avatar asked Nov 21 '10 13:11

alexyorke


2 Answers

I'm not sure I fully understand the question. I think you're saying you have an application (let's call it PrimaryApplication.app) and inside it's Resources directory there is an application you need to launch (let's call it Helper.app). In that case you use NSBundle's -bundlePath to get the path to the currently running application, then you append the path to your helper from there. You can use NSWorkspace to launch the application once you know the path to it.

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *helperAppPath = [[mainBundle bundlePath]
  stringByAppendingString:@"/Contents/Resources/Helper.app"];

[[NSWorkspace sharedWorkspace] launchApplication:helperAppPath];
like image 148
d11wtq Avatar answered Nov 10 '22 18:11

d11wtq


In Core Foundation, CFBundleCopyResourceURL should get you the application's url.

In Cocoa, NSBundle has equivalent pathForResource:ofType: and URLForResource:withExtension: methods.

like image 21
Richard Avatar answered Nov 10 '22 16:11

Richard