Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Launch another application from Cocoa?

Launch another application from Cocoa?
Thread Tools
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Dec 5, 2002, 06:46 PM
 
What's the recommended way to Launch an existing Mac OS X application from within a Cocoa application? I don't want to send it any arguments, just launch it and make it the frontmost application.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Dec 5, 2002, 07:48 PM
 
Here you go:

[[NSWorkspace sharedWorkspace] launchApplication:@"App"];

It'll automatically be frontmost.
you are not your signature
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Dec 5, 2002, 07:56 PM
 
Originally posted by Gametes:
Here you go:

[[NSWorkspace sharedWorkspace] launchApplication:@"App"];

It'll automatically be frontmost.
Wow, that was simple. I've not looked into workspaces at all. I'd better look up the doco, just so I understand exactly what this is doing.

Thanks!
     
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Dec 6, 2002, 11:46 AM
 
If you want to launch an app from an object that only includes the Foundation, without having to use the AppKit, you can also do this:

Code:
NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/Mail.app"]; // or whatever app NSString *path = [bundle executablePath]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:path]; [task launch]; [task release]; task = nil;
More lines of code than Gametes' suggestion, to be sure, but it's handy if you don't want to include the AppKit for some object.

[edit: damn vB code, turning things that aren't supposed to be smileys into smileys...]

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Dec 6, 2002, 03:26 PM
 
I've been wondering about the import dynamic in Cocoa. I mean, in an old-school C++ app, one would have to "#include" a needed file, which would actually insert the contents of the files into the final build, in order to ensure the code was there on whatever machine was running the app.
But in Cocoa, there is an absolute certainty that Apple's Appkit and Foundation frameworks will be on every machine. One has to physicially include private frameworks in the app, but linking to Cocoa shouldn't do anything to the size of the file, right? After all, why would doing so change it, since cocoa isn't actually included in the app?

I concede that if you don't use appkit, you shouldn't import it, but I don't understand why. It seems like it should be irrelevant.
you are not your signature
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:26 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2