Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active December 17, 2015 20:12
Show Gist options
  • Select an option

  • Save kristopherjohnson/ea3d40232fb31daa61c6 to your computer and use it in GitHub Desktop.

Select an option

Save kristopherjohnson/ea3d40232fb31daa61c6 to your computer and use it in GitHub Desktop.
Swift script to retrieve the info.plist dictionary for an executable
#!/usr/bin/swift
// Gets the info.plist data for executables specified on command line
import Foundation
if Process.argc < 2 {
print("usage: get-info-dictionary EXECUTABLE...")
}
else {
for i in 1..<Int(Process.argc) {
let arg = Process.arguments[i]
let url = NSURL(fileURLWithPath: arg)
let cfdictref = CFBundleCopyInfoDictionaryForURL(url)
if cfdictref != nil {
let infoDictionary = cfdictref as NSDictionary
print("\(arg):\n\(infoDictionary)")
}
else {
print("\(arg): no info dictionary")
}
}
}
@kristopherjohnson
Copy link
Author

Example:

chmod +x get-info-dictionary.swift
./get-info-dictionary.swift /Applications/Xcode.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment