Application icon

Hi,

In my application, it’s possible to change the icon from a menu in the Preferences pane.

For info:


    property pref_AppIcon : missing value -- menu
    property pathNewIcon : missing value
    property pathOldIcon : missing value

    on applicationWillFinishLaunching_(aNotification)
		set pathOldIcon to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Icon", "icns") as string)
    end applicationWillFinishLaunching_

    on changeAppIcon_(sender)
		if (pref_AppIcon's indexOfSelectedItem()) is 0 then
				set pathNewIcon to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Icon00", "icns") as string)
		else if (pref_AppIcon's indexOfSelectedItem()) is 1 then
				set pathNewIcon to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Icon01", "icns") as string)
		else if (pref_AppIcon's indexOfSelectedItem()) is 2 then
				set pathNewIcon to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Icon02", "icns") as string)
		else if (pref_AppIcon's indexOfSelectedItem()) is 3 then
				set pathNewIcon to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("Icon03", "icns") as string)
		end if
		do shell script "ditto -rsrc " & "/" & quoted form of pathNewIcon & space & "/" & quoted form of pathOldIcon
    end changeAppIcon_

It works. The icon is changed into the application but after relaunching the Finder, the Dock, and the application, there is always the old icon in the Finder’s window and in the Dock.

I didn’t have this problem with Leopard, Snow Leopard, Lion, and Moutain Lion.
Now with Mavericks, I must be restarted… :frowning:

If you have a solution without restart… Thanks a lot!

:cool:

Hi,

I’m just guessing here, but maybe your issue is with how Mavericks caches preferences. See this post on MacWorld:

http://hints.macworld.com/article.php?story=20130908042828630

In the Info.plist for your app (inside your .app bundle), there should be a key for your app icon. Maybe try updating this key after the ditto shell script.

Thanks x74353.

The key’s value in the Info.plist don’t change. :frowning:

Perhaps this will be relevant to your issue:

http://proteo.me.uk/2011/08/mac-application-bundle-caching/