Launch another App from your Storyboard App

David Garces
David codes (swift)
2 min readOct 21, 2015

This is a short article about my small and quick app that execute another app. If you know the Bundle identifier of the external app you want to launch, you can easily test if the app is running, and launch it using NSWorkspace.sharedWorkspace().

Implementation

There are two main steps you should add to your application:

  1. You should make sure the other application is not running
  2. If it is running you can send a message to the user informing them about this, otherwise you can launch the app and send the result to the user (if required).

This is a snapshot of the code I used to accomplish this, but you can easily download a sample app from: https://github.com/gbdavid2/DavidCodesOSX/tree/master/LaunchAppExample

// Check if main app is already running; if yes, do nothing and terminate helper app
var isAlreadyRunning = false
let running = NSWorkspace.sharedWorkspace().runningApplicationsfor app in running {
if app.bundleIdentifier == bundleIdentifierTextField.stringValue {
isAlreadyRunning = true
}
}
if !isAlreadyRunning {
let path = NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier(bundleIdentifierTextField.stringValue)let result = NSWorkspace.sharedWorkspace().launchApplication(path!)appPathTextField.stringValue = path!resultTextField.stringValue = result ? "App launched!" : "App didn't launch :("
} else {
resultTextField.stringValue = "App is already running"
}

The app will ask you to write your bundle identifier and will search for another app that uses this bundle identifier before launching it:

LaunchAppExample

Getting Bundle Identifiers

For this sample App I used Apple's default bundle identifier for the Maps App. If you don't know the bundle identifier of the app you need to execute, you may be able to get it by running a script as detailed in this question in StackOverflow.

--

--