Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are numerous ways to accomplish this, using Launch Services and or <code>NSWorkspace</code>.</p> <p>One of the more flexible ways to identity a bundled application is via its bundle identifier (<code>CFBundleIdentifier</code>), which is a string like <code>com.apple.TextEdit</code>. 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 use <code>NSWorkspace</code>'s <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWorkspace/launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:" rel="nofollow noreferrer"><code>launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:</code></a> to launch the app. If you don't already know it, you can obtain the bundle identifier of an application bundle by checking its <code>AppName.app/Contents/Info.plist</code> file. Then use the following code:</p> <pre><code>if (![[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"com.apple.TextEdit" options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:NULL launchIdentifier:NULL]) { NSLog(@"launching app failed!); } </code></pre> <p>Important: <code>NSWorkspace</code> is part of the <code>AppKit.framework</code> 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.</p> <p><img src="https://i.stack.imgur.com/CaQfT.png" alt="enter image description here"></p> <p>Add both <code>AppKit.framework</code> and <code>Cocoa.framework</code>.</p> <p>That will result in all 3 being listed in the Link Binary With Libraries step. At that point, you can remove both the <code>Foundation.framework</code> and <code>AppKit.framework</code> from the linking stage, and leave just the <code>Cocoa.framework</code>, like below:</p> <p><img src="https://i.stack.imgur.com/8CoI5.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload