1

I am working on a project, which require to change App icon at runtime. I have set default_icon.icns as default App icon.

Now when i want to change icon of App, I am using below code snippet in Appdelegate.m class.

NSString *iconPath = @“ ICON_PATH/new_icon_file.png ”;
NSImage *icon =[[NSImage alloc] initWithContentsOfFile:iconPath];

if (icon != nil)
{
    NSLog(@“Changing App icon");
    [NSApp setApplicationIconImage:icon];
}

When I run this project on 10.9.4 OSX,App Icon is not changing at run time, until i restart my Mac machine. After restarting mac machine, App default_icon is replaced with new_icon_file.

But above code snippet was working fine till 10.8 Mac OSX, There was no need to restart Mac machine and after executing “[NSApp setApplicationIconImage:icon]” line in code. default_Icon get replaced with new_icon_file.

Please correct me if there is any problem with above code snippet for changing App icon at run time?? or, Is there any other way to Change AppIcon at run time in 10.9 Mac OSX??

Thanks.

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
varun
  • 25
  • 7

1 Answers1

2

this method is not meant to change the finder app icon.

the docs state:
"...temporarily change the app icon in the dock app tile."

so if it worked that was a bug / at least unspecified behaviour.


what works is setting the icon for the app dir:

use NSWorkspace
there is - (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options

example of the top of my head
[[NSWorkspace sharedWorkspace] setIcon:[[NSBundle mainBundle] bundlePath] options:0];

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Can you please suggest me how to change finder App icon in MacOSX 10.9? – varun Sep 11 '14 at 07:10
  • @varun did this update the dock icon at the same time? when i replace the icon image in the .app programtically then toggle "Keep in Dock" it makes the dock icon update its icon to the new icon but i cant figure out how to progrmatically toggle "Keep in Dock" – Noitidart Feb 05 '15 at 16:05
  • 1
    @Noitidart No. I am not updating Dock Icon at rum time. Just go through http://stackoverflow.com/questions/6998485/modify-info-plist-to-set-application-is-agentuielement-at-runtime . May be it will help you to solve your issue. – varun Feb 07 '15 at 03:31