I am developing an application in Cocoa. I need to create a DMG file to install my application like Adium (which provides a nice UI to drag the app file to Application folder). Is there a tool for this?
-
7To whomever voted to close this, I'd disagree that this /necessarily/ belongs on SuperUser.com, just because there are programmatic ways to accomplish it, and it's more related to programming than end users, since this it about app deployment. – Quinn Taylor Aug 06 '09 at 17:43
-
1If a DMG isn't really necessary, use a zip. This is much less confusing to new Mac OS X users than a DMG. – Aug 03 '11 at 11:16
8 Answers
If you have a single file that the user would probably copy to the Applications directory, an "internet-enabled" disk image is a nice alternative. When you download one using Safari (I know, not everyone uses Safari), it automatically mounts it, copies the contents to the download location, then unmounts the DMG and moves it to the trash. The application doesn't automatically go to Applications, but it's on the user's HD and they don't have to worry about fiddling with the disk image.
Disk images can be internet-enabled with a single Terminal command:
hdiutil internet-enable -yes "MyDiskImage.dmg"
This should work on any DMG file. If you want users to see your pretty background, you might not want to do this. However, for simple payloads it's a nice way to go. (Of course, some people would prefer to create a ZIP file for this sort of deployment, anyway.)
I find that manually creating a DMG can be a pain. You can actually automate creation of a simple DMG in your Xcode project. Just create a Shell Script Target (Project → New Target...) and use hdiutil
in the script. The command would look something like this (substituting the proper names and directories):
hdiutil create -fs HFS+ -volname "MyApp 1.0" -srcfolder \
"/directory/with/contents/to/package/" "~/Desktop/MyApp-1.0.dmg"`
You'll need to put all the stuff you want to include in the disk image in a single directory, but if you're not afraid of using cp
in Terminal, this is easy to do.
If you would like to see an example, I use this approach in CHDataStructures.framework myself. If you check out the code and open in Xcode, the second script in the Deployment target creates the DMG.

- 44,553
- 16
- 113
- 131
-
2Alas, the Internet-enabled setting is [only followed](http://c-command.com/dropdmg/manual-ah/internet-enabled) by Mac OS X 10.2 through 10.6. And even on those versions, it pretty much only works when the .dmg file is downloaded by Safari. – Michael Tsai Sep 26 '13 at 11:50
Disk Utility (It's in Applications\Utilities)
Go to File
> New
> Disk Image From Folder
, then select the folder you want to create an image of. The resulting .dmg will replicate the folder you used to make the image, down to the positions of the icons.

- 507,862
- 82
- 626
- 550
-
2
-
This method does not, actually, preserve the top-level icon positions and view options. – Michael Tsai Mar 27 '11 at 01:24
-
@MichaelTsai Yes it does, you need to position everything, then convert it to compressed from Disk Utility, also to create a background image create a folder named `.background`, place your image in there, open up your volume, press `cmd+j` then mark `Background:Picture`, and drag the file in `.background` into it. this must be done before you convert it to a compressed (readonly) image. – Mostafa Berg Sep 25 '13 at 12:01
-
@MostafaTorbjørnBerg The answer above says that using that Disk Utility command will replicate the icon layout in the folder. That’s not correct. You have to position everything manually after creating the .dmg (each time you create the .dmg), and then you have to convert it to the compressed format. – Michael Tsai Sep 26 '13 at 11:43
-
Dr. Nic put together a nice ruby gem that does most of this work for you, you just need to supply the xcode project and some graphics. The link is here:
http://drnicwilliams.com/2009/02/03/choctop-packaging-and-deployment-of-cocoa-applications/
It is a great package, takes care of tasks that are otherwise a pain...
-- Evan

- 412
- 3
- 7
-
-
I have to mention that overall size of dmg created by this tool, increases up to 10M. – Bojan Babic Jun 26 '12 at 18:03
-
This seemed promising, but all the images and videos are dead links, the source was last updated 7 years ago, and it says it requires Sparkle... – Ky - Aug 02 '18 at 14:16
And because there aren't enough answers already...
I created a read-write DMG with the layout I wanted -- background image, size, shortcut to Application icon, and an empty folder to stand in for my application. I wrote a simple bash
script to make a copy of this DMG, mount it, copy my application over the empty folder, unmount the DMG, and then convert it to read-only.
But DMG Canvas can do this whole process for you, and also provides a command line tool you can use to automate this process from your Xcode builds, so I would really recommend that over my solution.

- 26,829
- 3
- 55
- 74
Mozilla build scripts are a great source if you want to write your own script. Using pkg-dmg you can customize the background image, the volume name, add a license, icon, etc. Example:
pkg-dmg \
--verbosity 2 \
--volname "MegaFinder" \
--source MegaFinder.app \
--sourcefile \
--target MegaFinder.dmg \
--license Licence.txt \
--icon MegaFinderVolumenIcon.icns \
--copy MegaFinderCustomizedDS_Store:.DS_Store \
--mkdir .background \
--copy MegaFinderBackgroundImage.jpg:.background/backgroundImage.jpg \
--symlink /Applications:Applications \
--attribute V:.background \
2>&1 > /dev/null
The problem is creating the perfect .DS_Store
. For simple cases you can create .DS_Store
customizing the mounted dmg volume in Finder (Show View Options). You'll need to create a writable image, customize it, unmount (to commit changes) and finally mount again to copy the resulting .DS_Store
as MegaFinderCustomizedDS_Store
(as it appears in above example)
If your app suppports Leopard I recommend DMG Canvas to manage the whole process or at least to obtain the .DS_Store
. It has a command line tool too.
-
Updated link to Mozilla scripts source: http://hg.mozilla.org/mozilla-central/file/tip/build/package/mac_osx – ash Sep 17 '13 at 16:17
-
The best way to do this as an automatic build step is to create a template.dmg that looks exactly how you want (using finder/diskutility etc but not doing the last step of compressing it), then in your build script:
- Use hdiutil to attach the image
- Use cp etc to copy the application into the mounted image
- hdiutil detach
- compress the image: hdiutil convert "in.dmg" -quiet -format UDZO -imagekey zlib-level=9 -o "MyApp-0.3.dmg"
There's a makefile at https://github.com/remko/fancy-dmg/ that contains these steps.

- 37,173
- 19
- 130
- 154
MacBreak Dev did a nice little screencast about creating DMG files using an Automator workflow. Makes things very easy, very quick and you can have a custom background to your DMG. You can see it at: http://www.pixelcorps.tv/mbkd_010

- 1,363
- 1
- 15
- 27
You can use DropDMG to set up a layout with a background picture, a symlink to the Applications folder, your icon positions, etc. Then, when you need to make your .dmg file, you can just drag the app onto DropDMG (or script it via AppleScript or the dropdmg command-line tool) and have it build the disk image in one step.

- 1,945
- 17
- 41