Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created May 19, 2015 13:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sindresorhus/c60ef57222b253b4a454 to your computer and use it in GitHub Desktop.
Save sindresorhus/c60ef57222b253b4a454 to your computer and use it in GitHub Desktop.
CLI to get the path to an app
import AppKit
func getPath(app: String) -> String? {
let workspace = NSWorkspace.sharedWorkspace()
if app.rangeOfString(".") != nil {
return workspace.absolutePathForAppBundleWithIdentifier(app)
} else {
return workspace.fullPathForApplication(app)
}
}
if Process.arguments.count == 1 {
exit(1)
}
let ret = getPath(Process.arguments[1])
if ret != nil {
println(ret!)
} else {
exit(2)
}
// Compile with: swiftc main.swift -emit-executable -sdk $(xcrun --show-sdk-path --sdk macosx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment