Skip to content

Latest commit

 

History

History
104 lines (53 loc) · 2.05 KB

how-to-create-dmg.md

File metadata and controls

104 lines (53 loc) · 2.05 KB

How to create dmg file?

What is a dmg file?

A file with the dmg extension is an Apple Disk Image file. When opened, an Apple Disk Image is mounted as a volume within the Finder.

For this reason, a dmg file is often the file format used to store compressed software installers instead of having to use a physical disk.

Four ways to create dmg file

node-appdmg is a package to generate beautiful DMG-images for your OS X applications.

Install

npm install -g appdmg

Usage

appdmg <config-json-path> <dmg-path>

create-dmg is a shell script to build fancy DMGs.

Install

brew install create-dmg

Usage

create-dmg [options ...] <output_name.dmg> <source_folder>

3. Create dmg manually

Open Disk Utility app on your Mac;

Click the File menu at the top left of the window;

Select New Image -> Image from Folder ... , Select the source file you want to convert to dmg file;

Enter the name of the export dmg file;

Click Done .

4. Exploit hdiutil command

hdiutil is a command line to manipulate disk images (attach, verify, create, etc).

For more detail, read this answer.

A demo script to create dmg for your application:

#! /bin/bash

set -x
set -e

AppName="myAppName"
VolumeName="myAppInstaller"

xcodebuild build -configuration Release

# make sure .app file exist
test -d ./build/Release/${AppName}.app || exit 1

# if the target dmg file exist, remove it
test -f ${AppName}.dmg && rm ${AppName}.dmg

hdiutil create -megabytes 54 -fs HFS+ -volname ${VolumeName} ${AppName}.dmg
hdiutil mount ${AppName}.dmg

cp -r ./build/Release/${AppName}.app /Volumes/${VolumeName}

Conclusion

Using the Disk Utility is the sampest way to create a dmg file.

Use the third-party package node-dmg or create-dmg can provide more configuration.