This is a very useful technique for distributing something to Mac users where presentation is everything. Disk Images (.dmg) are great for distributing various types of files/data/applications/etc., since they can compress, work great on the Internet, have great visual features, and work well with the Unix tricks the Mac has.
I’m assuming you’re running Leopard in the following instructions. This will work with a default install - no developer tools required, but there are some advanced tricks that use them (entirely optional).
1. Create the blank image:
Open the “Applications” folder, and launch “Disk Utility” from the “Utilities” folder. Click “New Image” in the toolbar (or “New Blank Image” from the File > New menu.
You can save the image file wherever you wish. The “Volume Name” will be the name of the resulting “disk”, and “Volume Size” is the maximum amount of data you’ll be able to hold (you can always compress it down later). To size it below 10 MB, you must change the “Volume Format” to not be “Journaled” (“Mac OS Extended”). If you’re just playing around, or just shipping a small program, 5 MB should be fine. No encryption, “Single partition - Apple Partition Map”, and “read/write disk image” will be the ideal settings. Then, click “Create”.
The file will save, and automatically mount the “disk” to your desktop.
2. Add the contents:
You’ll need to drag your contents to the new disk, and arrange them accordingly. If you want to have custom icons, background images, etc., those must be copied to the disk as well. if you have a background image, it’s a good idea to put that into a folder called “background”, and I’ll show you how to hide that…
3. Change layout/background:
Double-click the disk on the desktop to open it, if it isn’t already open. Switch the window to Icon View. Click the capsule to hide the toolbar.
Click the “View” menu, and Show View Options. Check the box for “Always open in icon view”. You can now tweak icon sizes, layout, and labeling to fit your taste. You’ll also be able to choose the background image from the “background” folder you made on the disk image, if you have one.
3b. Hide background folder:
Okay, you’ll need the Apple Developer Tools (XCode, etc.) installed for this:
Open Terminal (in the “Utilities” folder), and type the following:
/Developer/Tools/SetFile -a V /Volumes/your_custom_disk/background
Obviously, change “your_custom_disk” and “background” to whatever you need to hide the desired folder.
The above command is actually the easier way, in Leopard, to hide folders safely. You could also add a dot to the beginning of the folder name, but Finder doesn’t allow this, and it’s deprecated behavior (though still supported for now).
3c. Make an alias to the Applications folder: (optional)
This is easy. Simply create an alias to the Applications folder on your Mac, and drop it in the disk image, next to your application’s icon.
3d. Your own icon (optional):
If the icon is applied to another file or folder, just “Get Info” on that item, click the icon in the upper-left corner of the window, and press Command-C to copy the icon. Click the icon in the “Get Info” window of your target disk, and paste the icon with Command-V.
4. Get it down to size:
The computer can make your DMG even more efficient by compressing it.
Eject the disk image, but keep the DMG file handy.
Launch “Disk Utility” again (like above), and choose “Convert”. Find your DMG file, and click “Convert”. It will ask you to save the file somewhere. Make sure “Image Format” is “Compressed”, and “Encryption” is “none”. Save the DMG. It should be at least somewhat smaller than what the original was. Oftentimes, it’s dramatically smaller.
Tada! You’re all done!
Other links/tips: