HOW TO ASSOCIATE APP ICONS WITH FLTK OSX APPLICATIONS v0.91 11/11/2002, Greg Ercolano ----------------------------------------------------- On the Mac, application icons are part of the .app bundle for your app. So when the Finder, Dock, or a Desktop Shortcut wants to show your app, it will use the icons that are provided in your application's .app directory. 1) Start with the correct directory structure for the .app directory. 1a) Make the directories needed for the released application: mkdir foo.app mkdir foo.app/Contents mkdir foo.app/Contents/Resources mkdir foo.app/Contents/MacOS echo APPLnone > foo.app/Contents/PkgInfo It is important to use /this directory structure/, or the finder won't show and run your app correctly. In the above and all of the following, change the word 'foo' to the actual name of your app's executable. 1b) Copy your program's executable into the "MacOS" directory: cp foo foo.app/Contents/MacOS/ 1c) Create the ascii Info.plist file: foo.app/Contents/Info.plist ..which tells the finder and Dock where to find your icons, the name of your program. In real world conditions, this file can be long, to make the program responsive to AppleScript, drag+drop, etc. But in this case, just the bare bones that gets us an icon for the app: CFBundleName foo CFBundlePackageType APPL CFBundleVersion 59 CFBundleShortVersionString 1.1 CFBundleIconFile icons.icns CFBundleSignature none ..the only thing you must change is 'foo', which should be the name of your app. This name appears in your app's "Main Menu" bar. 'icons.icns' refers to a binary 'icon' file you'll save from IconComposer (instructions below) as this path: foo.app/Contents/Resources/icons.icns The name can be different; make sure the filename agrees with the Info.plist file. 2) Invoke "IconComposer" to import the application's icon. open /Developer/Applications/IconComposer.app It is assumed you have already created a nice icon, in accordance with Apple's artistic recommendations. (See REFERENCES below, #4 and #5) At very least, have a square icon with a matte channel saved as a PNG file. It's recommended you created the icon optimized as a 128x128 image. For best results in the finder, it's recommended you have also made a 48x48 and 16x16 version of the same icon, touched up to look good at those resolutions, so the Dock can interpolate between the resolutions nicely. I've found GIMP is great for making the PNG icons. 3) In IconComposer, use File -> Import to load your PNG icon(s). The program lets you load multiple icons, and in the Import file browser, lets you choose what the destination resolution will be for the file you're loading. If the file isn't already that size, IconComposer will prompt that it can rescale it for you. 4) Import as many icons as needed. At /minimum/ give it a 128x128 icon, so the dock can scale it down. However, I recommend using a 16x16, 32x32 and 128x128 icon, as that is what Mac OSX's own Terminal program uses. DIGRESSION: You can prove this to yourself by browsing the Terminal application's icons file using the "icns Browser" [sic] utility: open /Developer/Applications/icns\ Browser.app/ Use File -> Open to open the Terminal's icon file: /Applications/Utilities/Terminal.app/Contents/Resources/icon.icns 5) File -> Save the result into the icons.icns file, eg: foo.app/Contents/Resources/icons.icns 6) That's it. The 'foo.app' directory should show up in the finder as 'foo', with your icon on it, and you should be able to: o Double click on 'foo' to run your app. o Drag 'foo' onto the desktop. o Drag 'foo' onto the Dock, and watch it animate the size..! If the Finder /doesn't/ show your foo.app directory as 'foo' with your icon, then you might need to 'wake up' the finder by restarting it. I found that just 'kill'ing the Finder process works fine: 1) Find the pid of the Finder: # ps axww | grep Finder 8125 ?? S 0:03.72 /System/Library/[..]acOS/Finder -psn_0_4325377 8141 std UV+ 0:00.84 grep Finder 2) Kill it: # kill 8125 (Finder goes away, then comes back) ..this will cause the finder to definitely reload your icon. If the Finder shows your app as a folder, then you did something wrong when you created the directory tree, or the files in it. Check filename case, permissions, and contents for errors. CAVEATS ------- Of interest; you can make the GUIs accessable from the terminal command line by making a small wrapper script in a 'bin' directory, eg: cd /usr/local/bin cat > foo << EOF #!/usr/bin/perl exec("open /some/path/foo.app"); EOF chmod +x foo ./foo This way terminal users can invoke the program like any other unix program, ie. without needing to type 'open' and an absolute path. NOTE: I don't think there's currently any way to pass command line arguments through 'open', when used as above. This will (hopefully) change in future releases. Beware too: OSX may pass a weird "-psn" command line argument to your app when invoked via 'open', eg. 'foo -psn_0_12345' REFERENCES ---------- Sorry if these links go stale; if they do, you can probably use the text of the URL to redo a google search to find where they've moved. 1. Apple Tech Note 2013, describing the Info.plist file.. http://developer.apple.com/technotes/tn/tn2013.html 2. Apple release notes on Info.Plist: http://developer.apple.com/techpubs/macosx/ReleaseNotes/InfoPlist.html 3. Usenet: David Oster's 10/20/2001 Posting to comp.sys.mac.oop.powerplant Subject: 128x128 OS X icons in PowerrPlant. [sic] http://groups.google.com/groups?hl=en&frame=right&th=10dcf01f8f9209de&seekm=oster-A7EF9A.01085720102001%40news.sf.sbcglobal.net#s 4. Apple: "Learning Carbon", Chapter 13: Desktop Icons http://developer.apple.com/techpubs/macosx/Carbon/HumanInterfaceToolbox/IconServUtili/DesktopIcons/ch13.html 5. Apple: Aqua Human Interface Guidelines: Icons http://developer.apple.com/ue/aqua/icons.html