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 = [NSURL URLWithString:@"/Applications/Calculator.app"];
NSLog(@"%@", path);
NSImage *image = (__bridge NSImage *)(QLThumbnailImageCreate(kCFAllocatorDefault, (__bridge CFURLRef)(path), CGSizeMake(100, 100), (__bridge CFDictionaryRef)(@{(NSString *)kQLThumbnailOptionIconModeKey: @NO})));
NSLog(@"%@", image);
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];
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_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With