Created
May 19, 2015 13:17
-
-
Save sindresorhus/c60ef57222b253b4a454 to your computer and use it in GitHub Desktop.
CLI to get the path to an app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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