How do I get the icon from another application using Objective-C?
I have tried this so far, however it just returns null
:
NSURL *path = [NSU
You can use NSWorkspace, e.g.
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFile:path];
If you want to use the app bundleId
instead of knowing its path, you can do this first
path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleIdentifier];
The icon file of an application is usually defined in its Info.plist under the CFBundleIconFile key. By obtaining the icon file name, you can then get this icon from the Resources directory of a bundle (path-to-anApplication/Contents/Resources/).
To get the Info.plist contents, you can either load it directly in an NSDictionary (using dictionaryWithContentsOfFile:) or get it from the bundle object of the application (example : [[NSBundle bundleWithPath:path-to-anApp] infoDictionary])
.
The icon file will be the value of the CFBundleIconFile key (i.e.: iconFile = [infoDictionary valueForKey:@"CFBundleIconFile"]
. Its path will then be : path-to-anApplication/Contents/Resources/iconFile).
I think you're looking for [[NSWorkspace sharedWorkspace] iconForFile:pathToFile]
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-iconForFile_