In Xcode 4.6, I created a new application based on the "Command Line Tool" project template.
How can I programmatically start another application (.app application bundle) from that "Command Line Tool" app?
In Xcode 4.6, I created a new application based on the "Command Line Tool" project template.
How can I programmatically start another application (.app application bundle) from that "Command Line Tool" app?
There are numerous ways to accomplish this, using Launch Services and or
NSWorkspace
.One of the more flexible ways to identity a bundled application is via its bundle identifier (
CFBundleIdentifier
), which is a string likecom.apple.TextEdit
. This allows you to identify an application without having to hard-code an assumed path where the application will be found, or by hard-coding the name of the application bundle, both of which a user could easily change. You can useNSWorkspace
'slaunchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:
to launch the app. If you don't already know it, you can obtain the bundle identifier of an application bundle by checking itsAppName.app/Contents/Info.plist
file. Then use the following code:Important:
NSWorkspace
is part of theAppKit.framework
framework, which is not initially included in the "Command Line Tool" project template. To add it to your project, select the target in the list of targets like shown in the image below, and click the + button to add additional frameworks.Add both
AppKit.framework
andCocoa.framework
.That will result in all 3 being listed in the Link Binary With Libraries step. At that point, you can remove both the
Foundation.framework
andAppKit.framework
from the linking stage, and leave just theCocoa.framework
, like below:Have you tried "open"? At least in terminal "open" runs files and/or apps.