get icon of file/folder/app

I tried almost everything to get the icon of a file/folder/app and nothing worked. I wrote about this topic in this forum, but no one had a solution.
I’ve found some ideas to get the icon using objective-c methods. I know that this is not an objective-C forum, but it could be very usefull to all applescript users to know how to get icon of file/folder/app… :oops:
that is what I’m trying, but it doesn’t work. Perhaps anyone could help me!

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@interface Icon : NSObject
- (NSImage*)getIcon:(NSString *)tmpImagePath;


#import "Icon.h"

@implementation Icon

- (NSImage*)getIcon:(NSString *)tmpImagePath    {
    NSImage *nodeImage = [[NSWorkspace sharedWorkspace] iconForFile:tmpImagePath];
	return nodeImage;


AppleScript call:

set a to call method "getIcon:" of class "Icon" with parameter "/Users/yourName/Desktop/AA"
set image of image view "Image" of window "Test" to load image a

One problem with icons in asstudio, is that cocoa and applescript don’t always refer to data in the same way. When you use a method like the one you posted, it returns an actual image object represented as data. When you call the method via applescript, it can be tricky to find the exact syntax that applescript can use to understand what the method returned. I find it better to make a reference to the object you want to display the image in, and then pass both the object reference and the image path to a cocoa method which will then handle putting the image in the view. Check out my second post in a thread from a while back, which should have the code your looking for.


But I’m working with data source for a table view (and the image view was for testing only). Do you know how to handle with it and your method to set the icon?