TweetFollow Us on Twitter

Ship It! Distributing Your Software

Volume Number: 20 (2004)
Issue Number: 1
Column Tag: Programming

Mac OS X Programming Secrets

by Scott Knaster

Ship It! Distributing Your Software

Here's a twist: let's assume your world-changing Mac OS X application is finished, documented, freshly painted, and ready to go out into the world. What are you going to do now? Why, you need to distribute your software, of course. We're going to take a couple of columns to look at how you get your software out into the world and installed on happy Macs everywhere.

There are two ways you can distribute your software: as a disk image, or wrapped in an installer. Mac OS X comes with Apple-supplied tools you can use to create both kinds of distributions, whether your software is going to get to users on a CD or via the Internet. In this month's column, we're going to cover the first kind of distribution: disk images.

In Your Image

If your software has just an application bundle to install, maybe along with some documentation or a couple of other ancillary files, you should consider providing drag-and-drop installation with a disk image. A disk image is simply a file that contains an encoded representation of a disk volume. Mac OS X can turn a disk image into something that looks exactly like a mounted volume. When you distribute a disk image online with your application on it, your users can download the disk image, have OS X mount it like a disk, then just drag your application from the volume and drop it on their own disks. You can also use a disk image to create CDs to distribute. When users get the CDs, they can drag and drop to install in the same way.

Writing and testing your software is hard - making a disk image that includes your software is very easy. When you're ready to start messing around with disk images, launch Disk Utility, which you'll find in the /Applications/Utilities/ folder. (If you're using Mac OS 10.2, use Disk Copy instead - the disk image creation features are in there. They're very similar to those in Disk Utility, but not identical. As a MacTech reader, we trust you can adapt.)

Note that even though Apple replaced the features of Disk Copy with Disk Utility in 10.3, not all of Disk Copy's features made it in. In particular, Disk Copy provided more options for your disk image format, and Disk Copy let you create an image from a folder by dragging the folder in (Disk Utility lets you do this via a menu item). Maybe these features will be revived in future versions of Disk Utility.

To make your new disk image, click New Image in the toolbar. You'll see a sheet like the one in Figure 1. Give your disk image a pleasant name. For the Size popup, choose a size that's big enough to hold the software you're going to put on it. It's OK if the virtual disk is way too big - if you're going to distribute it via the Internet, you can compress it later, so unused space won't be wasted. Leave the Encryption and Format settings as they are, and click Create. Disk Utility will show you a little progress dance, and then voila! You've created your first disk image (see Figure 2). After the image is created, OS X mounts it as a volume.


Figure 1. Disk Utility offers various settings when you create your disk image. Usually, you'll just have to worry about the size, making sure it's big enough for your files.


Figure 2. After you create your disk image, it appears in the left pane of Disk Utility and its image is mounted.

Build Your Case

Once you've created the disk image, switch to the Finder. You'll discover the Finder already knows about the volume supplied by your fresh new disk image. If you're running 10.3 and you have the Sidebar set to show removable media, your volume appears in the list. Now you need to add your files to it. Grab the files you want to distribute and drag them to the new disk.

After you've dragged and dropped the files, you can channel your inner designer and make the Finder window look just the way you want. Move the icons around to form a lovely pattern. Choose View --> Show View Options and add a background image or color, pick a different size for the icons, and make the labels look perfect.


Figure 3. In the Finder, drag the files you want to the disk image, then go wild dressing up the contents however you like.

Here are a couple of tips about prettying up the way your Finder window looks. The General panel of Finder preferences has a setting called Open new windows in column view. If the user has this checked, your disk image's window will indeed open in column view, which conceals all your painstaking icon placement and other visual tweaks. Sigh. Second, if you want to use a background picture (JPG, PNG, and so on) for your Finder window, make sure you copy the picture's file to your disk first, then use the Select button in the View Options window to point at the new copy. If you don't copy it to your disk first, it won't be there for users to see when they download your disk image or open your CD.

Once you have the files and the view settings you want, eject the disk image in the Finder and go back to Disk Utility. If you're going to distribute your software by CD, you can go ahead and order the pizza, because you're almost done. All that's left now is to burn the CD. You can do that from Disk Utility. Just select the disk image in the left pane and click Burn on the toolbar. Disk Utility will ask you to insert a blank CD, then give you the dialog you see in Figure 4. Just click Burn and wait for your CD to be made.


Figure 4. "Ready to burn," indeed! You'll get this

dialog when you have selected a disk image (.dmg) 

and inserted a blank CD.

Download Lowdown

If you want to get your disk image ready for online distribution instead of via CD, the first thing to do is get that extra space out of the disk image. To do this, while still in Disk Utility, select the disk image in the left pane (if it's not there, you can drag it in from the Finder, or choose Images --> Open), and then choose Images --> Convert. Pick Compressed as the image format, and let 'er rip. Soon you'll have your compressed image. (For fun, you can go into the Finder and Get Info on both the original and compressed images. You'll see that the original is 40 Mb, or whatever other value you specified when you created it, and the compressed version not only gets rid of the unused space, it compresses the files, so the image uses less space than the original files.)

You might notice that Disk Utility keeps track of all the disk images it has ever seen on its little shelf over in the left pane. The way to get rid of those isn't obvious: just drag them off and drop them anywhere but the pane, and they'll go poof.

Once you have the compressed image, you're done. You can post it online for downloading. Let's take a look at the experience users have when downloading a disk image with a web browser. If you download a disk image with a non-Apple browser, such as Internet Explorer or Camino, here's the typical experience:

    1. User clicks a link to download the disk image file. The file goes into the Downloads folder.

    2. In the Finder, in the Downloads folder, the user double-clicks the disk image. The Finder decompresses the disk image and mounts it. Usually, the disk automatically opens.

    3. The user drags the downloaded application to the hard disk, usually to the Applications folder.

    4. The user ejects the mounted disk image.

    5. The confused, exhausted user drags the disk image file to the trash.

When Safari appeared in January 2003, Apple made it smarter than the average bear for downloading disk images. Safari knows how to decompress and mount disk images all by itself, without having to ask the Finder for help. So when you download a disk image with Safari, there's one less step: you don't have to switch to the Finder and double-click the disk image file. That's progress.

Becoming an Enabler

When Mac OS 10.2.3 arrived, Apple made the download experience even better, as long as you were using Safari. Mac OS 10.2.3 introduced the groovy concept of Internet-enabled disk images, which make the download experience even better. When users download an Internet-enabled disk image, Safari decompresses the file and mounts the virtual disk, as usual. But then, it continues by copying the disk's contents to the Downloads folder, ejecting the mounted disk image, and moving the disk image file to the trash. That's pretty cool for users. All they have to do at that point is visit the files in the Downloads folder and copy them to their final destination. And Internet-enabled disk images are compatible with all browsers and Mac OS X versions. Users who are not running Safari with Mac OS X 10.2.3 or later will still get the old, standard behavior.

How do you make an Internet-enabled disk image? I was hoping you would ask that question. It's free and oh-so-easy. You merely have to issue a single instruction using hdiutil, a command line utility that comes with Mac OS X. To Internet-enable your favorite disk image, just go to the Terminal and type

   hdiutil internet-enable -yes SuperWare.dmg

Of course, make sure you have the right path to your disk image file. As always, you can drag the file into the Terminal window from the Finder if you want to be sure. If you do it right, hdiutil will confirm back to you thusly:

   hdiutil: internet-enable: enable succeeded

That's all there is to it. Sure, it would be nice if Disk Utility had a command for Internet-enabling, and it surely will in the future, but for now, this is how we do it. If you find distasteful even this extremely brief journey into Unix, you can use the donationware program IDIot, which makes it super-simple to Internet-enable a disk image. IDIot is available at http://www.ifthensoft.com/idiot.hqx . And if you want to read all about Internet-enabled disk images from the folks who invented them, see http://developer.apple.com/ue/files/iedi.html.

Master and Commander

As we have seen, Disk Utility makes it pretty darn easy to create disk images, and with just a little tweak under the hdiutil hood, we can improve the user experience by making disk images Internet-enabled. If you're the command-line type, or you need to write shell scripts to manipulate your disk images, you should consider hdiutil for more than just the bit part described above.

You can perform the same basic functions with hdiutil as you can with Disk Utility, plus lots more geeky stuff. For example, earlier we used Disk Utility to create a disk image, copy files to the image, then compress it for optimum online distribution. Let's do the same steps with hdiutil. First, we create the disk image itself and ask the operating system to mount it:

[neb:~] scott% hdiutil create -size 40m -fs HFS+ -volname "SuperWare" SuperWare.dmg

Initializing...
Creating...
...............................................................................
Formatting...
Finishing...
created: /Users/scott/SuperWare.dmg

[neb:~] scott% hdiutil mount SuperWare.dmg
Initializing...
Attaching...
Finishing...
Finishing...
/dev/disk2              Apple_partition_scheme         
/dev/disk2s1            Apple_partition_map            
/dev/disk2s2            Apple_HFS                       /Volumes/SuperWare

Note the aid and coddling that Disk Utility gave us when we used it previously. Disk Utility thoughtfully assumed we needed an HFS+ disk, wanted the volume name to be the same as the filename of the image, and would like to mount the new volume. When we use hdiutil, we have to explicitly choose the file system and volume name we want, and we need a second command to mount the volume. Of course, this little bit of extra work also indicates that hdiutil provides us with extra flexibility. For example, you can choose a different file system, or a volume name that's not the same as the file name when you use hdiutil. As an extreme example of the flexibility of hdiutil, it lets you specify the size of the disk image in various units, including megabytes, gigabytes, terabytes, petabytes, and exobytes. An exobyte is a gigabyte of gigabytes. That's thinking ahead!

At this point, we're ready to copy the desired files to the disk image. Of course, we can use the command line or the Finder for this, or both. You'll probably want to use the Finder for delicate icon positioning and tweaking Finder view settings. Once the disk image has everything you want, unmount it:

[neb:~] scott% hdiutil unmount /Volumes/SuperWare 
hdiutil: unmount: LetIOKitSettleDown: (timed out)
"disk2s2" unmounted successfully.

After unmounting, we can use hdiutil to burn a CD, like so:

[neb:~] scott% hdiutil burn SuperWare.dmg

Preparing data for burn
Opening session
Opening track
Writing track
.............................................................
Closing track
Closing session
Finishing burn
Verifying burn...
Verifying
.............................................................
Burn completed successfully
.............................................................

hdiutil: burn: completed

Burning a CD with hdiutil is like a game: you see how many dots you can get before more text appears. No fancy-pants Aqua progress bars here! If you're not going to burn a CD, but you instead want to prepare the disk image for downloading, you need to compress it, as we did with Disk Utility. With hdiutil, that works as follows:

[neb:~] scott% hdiutil convert -format UDCO -o SuperWare_online.dmg SuperWare.dmg

Preparing imaging engine...
Reading DDM...
   (CRC32 $767AD93D: DDM)
Reading Apple_partition_map (0)...
   (CRC32 $DD66DE0F: Apple_partition_map (0))
Reading Apple_HFS (1)...
.............................................................
   (CRC32 $9F4C65C5: Apple_HFS (1))
Reading Apple_Free (2)...
.............................................................
   (CRC32 $00000000: Apple_Free (2))
Terminating imaging engine...
Adding resources...
.............................................................
Elapsed Time:  1.074s
 (1 task, weight 100)
File size: 31489 bytes, Checksum: CRC32 $A3B0383C
Sectors processed: 81920, 1345 compressed
Speed: 626.0Kbytes/sec
Savings: 97.6%
created: SuperWare_online.dmg

In amongst all that geeky progress reporting, we've created our compressed image in the file SuperWare_online.dmg. The -format UDCO option is the way you create a compressed image. And by the way, if you would rather not see Terminal spew all that stuff at you, most hdiutil commands include a -quiet option to suppress output. To find out about all the features of hdiutil - and there are an enormous number of them - check out man hdiutil. Most hdiutil commands have their own individual help commands, which you can get by typing hdiutil, the command name, and the -help option, like this:

[neb:~] scott% hdiutil unmount -help
hdiutil unmount: unmount a mounted partition
Usage:  hdiutil unmount <mountpoint>
        Options:
            -force              force unmount

        Common options:
            -verbose
            -debug
            -quiet

Another powerful option for creating disk images is DropDMG, a $10 utility written by Michael Tsai. This program provides a nice Aqua UI with more disk image creation features than Disk Utility, has a thorough AppleScript dictionary, and is also available from the command line. You can get DropDMG at http://www.c-command.com/dropdmg/index.shtml.

You might also be interested in BootCD, a free utility for making disk images that create bootable CDs. BootCD is available at http://www.charlessoft.com/.

Coming Soon

As we mentioned at the start, disk images are only one way of passing out software. Disk images are great for distributions that are simple enough to allow drag-and-drop installation. However, drag installing leaves behind older copies of the application, which can confuse the Finder. And if you have more complex requirements, such as needing to put files in various places on the disk, run code while you're installing, or install on OS 9 as well as OS X, you'll need an installer.

You can use the PackageMaker and Installer tools provided by Apple, or get a more powerful third-party tool, such as Installer VISE, VISE X, or FileStorm from MindVision, or StuffIt InstallerMaker from Aladdin. Many commercial developers prefer those third-party programs for complex installations, but Apple's built-in tools are easy to use, improving, and free - if you have OS X, you already own them. In next month's column, we'll take a look at how to use these tools to create your own installers. Until then, get your software coded, tested, debugged, and documented, so you'll be all ready to distribute it.


Scott Knaster has been writing about Macs for as long as there have been Macs. Scott wrote developer books for General Magic, worked on SDK stuff for Danger, and contributed to the first user manual for the Philips Velo. Scott's hobby is gaining and losing weight.

 
AAPL
$101.79
Apple Inc.
+0.21
MSFT
$46.68
Microsoft Corpora
+0.16
GOOG
$589.27
Google Inc.
+4.50

MacTech Search:
Community Search:

Software Updates via MacUpdate

Xcode 6.0.1 - Integrated development env...
Apple Xcode is Apple Computer's integrated development environment (IDE) for OS X. The full Xcode package is free to ADC members and includes all the tools you need to create, debug, and optimize... Read more
Apple Safari 7.1 - Apple's Web brow...
Apple Safari in OS X Mavericks brings you all-new ways to find and enjoy the best of the web. It works with iCloud to give you a seamless browsing experience across all your devices. It looks out for... Read more
Delivery Status 6.1.2 - Check delivery s...
Delivery Status displays delivery status of packages for a variety of shipment services. Can't wait for your packages to arrive? Don't waste your time checking the site constantly, just open this all... Read more
Mavericks Cache Cleaner 8.0.9 - Clear ca...
Mavericks Cache Cleaner is an award-winning general purpose tool for OS X. MCC makes system maintenance simple with an easy point-and-click interface to many OS X functions. Novice and expert users... Read more
OneNote 15.2.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Apple Configurator 1.6 - Configure and d...
Apple Configurator makes it easy for anyone to mass configure and deploy iPhone, iPad, and iPod touch in a school, business, or institution. Three simple workflows let you prepare new iOS devices... Read more
SpamSieve 2.9.16 - Robust spam filter fo...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
OS X Server 3.2.1 - For OS X 10.9.5 Mave...
OS X Server is the next generation of Apple's award winning server software. Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, host... Read more
Apple Security Update 2014-004 - For OS...
Apple Security Update is recommended for all users and improves the security of Mac OS X. For information on the security content of this update, please visit this website: http://support.apple.com/... Read more
OS X Mavericks 10.9.5 - The latest versi...
Apple OS X Mavericks is the latest release of the world's most advanced desktop operating system. Now free! With more than 200 new features, OS X Mavericks brings Maps and iBooks to the Mac,... Read more

Latest Forum Discussions

See All

Down Among the Dead Men (Games)
Down Among the Dead Men 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Avast! Take to the high seas in a fully interactive piratical tale of broadsides and buccaneers. From author Dave... | Read more »
Sling Adds Chromecast Support Through Sl...
Sling Adds Chromecast Support Through Slingplaye​r Mobile Apps Posted by Jessica Fisher on September 18th, 2014 [ permalink ] | Read more »
How to Completely Delete Your iPhone’s C...
The iPhone 6 is out tomorrow, and plenty of people are excited about it. So much so that they’re planning to – or already have – traded in their old iPhone to go towards it. The thing about trading in hardware is it’s very important to make sure... | Read more »
Dragon Quest I Review
Dragon Quest I Review By Andrew Fisher on September 18th, 2014 Our Rating: :: THINE QUEST AWAITETHUniversal App - Designed for iPhone and iPad Its historical significance aside, Dragon Quest 1 is a fun, campy, difficult, thoroughly... | Read more »
It Came From Canada: Overkill 3
Overkill 3 is like every trope of big modern gaming rolled into one. It’s a sequel to an action-packed military shooter. It’s flashy and scripted and flaunts its sophisticated graphics. And it’s a mobile game with a heavy emphasis on in-app... | Read more »
New Modes and Leader Boards in Update fo...
New Modes and Leader Boards in Update for Rules! Posted by Jessica Fisher on September 18th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
TwistedRun Review
TwistedRun Review By Rob Thomas on September 18th, 2014 Our Rating: :: DON'T TWIST YOUR ANKLE!Universal App - Designed for iPhone and iPad TwistedRun is kind of like running up a giant curly fry into the sky. Or maybe that was just... | Read more »
Scope Review
Scope Review By Jennifer Allen on September 18th, 2014 Our Rating: :: LOCATION AWAREiPhone App - Designed for the iPhone, compatible with the iPad Want to easily find photos from around the world based on their location? Scope is a... | Read more »
HipstaFox Review
HipstaFox Review By Jordan Minor on September 18th, 2014 Our Rating: :: FANTASTIC MR. FOXUniversal App - Designed for iPhone and iPad HipstaFox is a great single that makes players long for the whole album.   | Read more »
Ninja Raft (Games)
Ninja Raft 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: ** Special Launch Price ** "Ninja Raft is definitely the game to play if you’re into Tower Defense games and want to play something... | Read more »

Price Scanner via MacPrices.net

Save up to $300 on the price of a new Mac wit...
Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more
13-inch 2.8GHz Retina MacBook Pro available f...
B&H Photo has the new 2014 13″ 2.8GHz Retina MacBook Pro on sale for $1699.99 including free shipping plus NY sales tax only. They’ll also include free copies of Parallels Desktop and LoJack for... Read more
16GB iPad Air on sale for $449, save $50
Walmart has the 16GB iPad Air WiFi on sale for $449 on their online store for a limited time. Choose free home shipping or free local store pickup. Their price represents a $50 savings over standard... Read more
13-inch 256GB MacBook Air on sale for $1099,...
B&H Photo has the 2014 13″ 1.4GHz 256GB MacBook Air on sale for $1099.99. Shipping is free, and B&H charges NY sales tax only. Their price is $100 off MSRP. Read more
Toshiba Introduces TransMemory ID High-Speed...
Toshiba’s Digital Products Division (DPD), a division of Toshiba America Information Systems, Inc., today introduced the TransMemory ID USB 3.0 Flash Drive, a simpler storage solution for people who... Read more
New iPads and OS X Yosemite Release Coming Oc...
The DailyDot’s Micah Singleton reports that Apple is planning to hold its next product announcement event on Oct. 21, at which it will unveil the iPad Air 2 and iPad mini 3 and release a final build... Read more
Logitech Bluetooth Multi-Device Cross-Platfor...
Logitech has an enviable track record of making some of the best computer keyboards and mice. At least in my estimation, the best freestanding keyboards I’ve ever used have been Logitech units,... Read more
Roundup of Apple refurbished iPad Airs and iP...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Sprint offers 16GB iPad mini for $199.99 with...
Sprint is offering 1st generation 16GB iPad minis for $199.99 with a 2-year service agreement. Standard MSRP for this iPad is $429. Their price is the lowest available for this model. Read more
2.5GHz Mac mini remains on sale for $549, sav...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more

Jobs Board

Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.