Search code examples
objective-cmacosnsworkspace

Change icon of alias on desktop?


I have an alias of an actual application on my desktop.

Now i have to change its icon at runtime. I'm using,

[[NSWorkspace sharedWorkspace] 
setIcon:imgAppIcon forFile: shortCutDestPath options:0];

But this changing icon of original file in/Application folder. Instead of alias changing.


Solution

  • I got the answer, instead of creating alias create a hard link at shortCutDestPath of your application:

     [[NSFileManager defaultManager] linkItemAtPath:<application path>
                                                    toPath:shortCutDestPath
                                                     error:&error];
    

    To update icon

    BOOL result = [[NSWorkspace sharedWorkspace] setIcon:imageIcon
                                           forFile: shortCutDestPath
                                           options:NSExclude10_4ElementsIconCreationOption];