Extract app icon

I’m trying to find a way to get at the icon for a Mac app.

The app will be selected by the user but I need to get at the icon of the chosen app, so that I can display it in my app.

I could do this easily in the old Mac OS 8 and 9 days but not sure there’s a clean way to do this in OS X. Any ideas gratefully received.

Open the bundle and look in the Resources folder. There’s a .icns file for each set of icons the app uses.

BTW, app icons and logos are often covered by trademarks in the U.S. Be careful what you use it for.

Manually to understand the path:

Right-click in the application,
choose open the bundle (whatever the text says, it means that),
open the Resources folder and search for it.
Once there, you have the path of the icon file.

Yeah, I meant from code :slight_smile:

Turns out that MacOSLib has the required functions. See MacIconWindow example. Thanks again MacOSLib people :slight_smile:

folderitem.IconMBS maybe?

Once you know where are the stuff and what to do, you only have to do the How… err. you only have to write the code.

It’s not as simple as getting the code to dig into various app bundles. Apple tend to name their icns files with the same name as the app, minus any spaces. But other developers may not. For example, I have FileMaker Pro on my hard drive - it’s icns file is named FM12App.icns.

But as I said, MacOSLib has the required functions to do this properly.

not really, in Yosemite Safari’s icon name is compass.icns

“Tend to…” :slight_smile:

Just look into /Content/info.plist :

<key>CFBundleIconFile</key> <string>compass</string>

[quote=154904:@Michel Bujardet]Just look into /Content/info.plist :

<key>CFBundleIconFile</key> <string>compass</string>[/quote]
Not sure it’s a great idea to be digging around inside the bundles of other apps. Macoslib seems to do it the proper way. And I’m sure Christian’s does too, to save him a post :wink:

I have used his iconMBS plugin. It rocks.

If you have the Retina Kit 2, it includes functions for getting file icons, either from a file or file type.

Dim appIcon as RKPicture = retinaKit.iconForFile( specialfolder.applications.child( "Mail.app" ) )

Will get you the app icon for Apple Mail.

Here is an Example of how I extract the icon with AppleScript