Last active
March 31, 2024 17:55
-
-
Save orchetect/e14b15392e2978cb23f50bc939394c64 to your computer and use it in GitHub Desktop.
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 | |
// 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment