Skip to content

Instantly share code, notes, and snippets.

@orchetect
Last active June 19, 2024 01:27
Show Gist options
  • Save orchetect/e14b15392e2978cb23f50bc939394c64 to your computer and use it in GitHub Desktop.
Save orchetect/e14b15392e2978cb23f50bc939394c64 to your computer and use it in GitHub Desktop.
import AppKit
// MARK: - App Icons
func getIcon(file path: String) -> NSImage? {
guard FileManager.default.fileExists(atPath: path)
else { return nil }
return NSWorkspace.shared.icon(forFile: path)
}
func getIcon(bundleID: String) -> NSImage? {
guard let path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleID)
else { return nil }
return getIcon(file: path)
}
func getIcon(application: String) -> NSImage? {
guard let path = NSWorkspace.shared.fullPath(forApplication: application)
else { return nil }
return getIcon(file: path)
}
// MARK: - Bundles
/// Easily read Info.plist as a Dictionary from any bundle by accessing .infoDictionary on Bundle
func bundle(forBundleID: String) -> Bundle? {
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: forBundleID)
else { return nil }
return Bundle(url: url)
}
@ejbills
Copy link

ejbills commented Jun 19, 2024

Thanks!

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