23

I want to create a dmg file for my Mac project. Can someone please tell me how to do this? This being my first Mac project, I do not have any idea how to proceed. I also want to give the user an option of running the app on start-up. How do I do this?

Thanks.

P.S. I also want to add a custom license agreement.

4 Answers 4

30

To do this manually:

Method 1:

  • Make a folder with the files your DMG will contain.

enter image description here

  • Open Disk Utility (It's in /Applications/Utilities/)

enter image description here

  • Go to File > New > New Image from Folder (Cmd + Shift + N)

enter image description here

  • Choose the folder containing you files
  • Make sure "Compressed" is checked, then set where you want to save the created DMG

enter image description here

enter image description here

enter image description here

Method 2:

To do things like setting a background image can be a bit convoluted (You basically add the background image to the DMG, set the windows properties to use that image, using the command line you move the background image from background.png to .background.png to make it hidden)

I would recommend iDMG, which makes things a bit less tedious.

You can also script the creation of DMGs using the command hdiutil. Something along the lines of

hdiutil create -srcfolder mydirtodmg mydmg.dmg

enter image description here

As for the custom license agreement, you should look into the tool included with the Developer Tools "PackageMaker" - it's pretty self-explanatory. It's in /Developers/Application/Utilities/

1
  • 2
    little correction: hdiutil create -srcfolder mydirtodmg mydmg.dmg
    – cnd
    Nov 25, 2015 at 9:13
8

If you need to add a custom EULA to your disk image, this page describes how to do so using command-line tools. The gist of it is to use the template software licensing agreement resource provided in Apple's slas_for_udifs_1.0.dmg, modify the resource with your EULA text and inject the resource back into your disk image file. (I include brief instructions below in case the above link becomes unavailable, and to update the search term it provides in step 1.)

  1. Using your Apple Developer account go to the Downloads page and search for Software Licensing for UDIF
  2. Download and mount the disk image
  3. In Terminal:

    cd /Volumes/SLAs_for_UDIFs_1.0
    DeRez SLAResources > /tmp/sla.r
    
  4. Edit /tmp/sla.r in a text editor, updating the content of the data 'TEXT' (5000, "English SLA") resource to contain your new license text.

  5. Unflatten the disk image file that contains your installer:

    hdiutil unflatten installer_image.dmg

  6. Add the edited license resources to the image:

    Rez -a /tmp/sla.r -o installer_image.dmg

4
  • Link requires a login :( Aug 21, 2015 at 22:10
  • Looks like the site has changed since I originally posted the answer. I've updated the link to refer to an 'Internet Archive' copy (which doesn't require a log in). Aug 23, 2015 at 2:46
  • I've actually decided to update the answer to include explicit instructions for easy reference. Also, the linked page refers to a search term that no longer works on the Apple Dev site. Aug 23, 2015 at 3:09
  • I followed the steps as you mentioned, however I was two issues. 1. By default my License is displayed in french 2. Edit test is not appeared in the EULA. Any pointers on it?
    – Anni S
    Dec 28, 2015 at 10:59
4

why don't you just run a script from your xcode project. try something like this:

# be sure to check the man page for hdiutil
# it is very powerful and has tons of options...

hdiutil create -megabytes 54 -fs HFS+ -volname awesome_app_install myAwesomeApplication.dmg
hdiutil mount myAwesomeApplication.dmg
cp -r /build/Release/AwesomeApplication.app /Volumes/awesome_app_install/

then save your script as something like 'makeDMG.sh' and in your target,

select add->new build phase->run script build phase
and drag your script into this build phase.

once you've done all that, then when you build your project the script will create the disk image and copy your release build into it...

of course you should spice your script to flavor... these three lines are just the raw meat

ps: your custom EULA should get built into your packagemaker project (which you can also script very nicely)

0

I made a little bash script to automate a disc image creation.

It creates a temporary directory to store all needed files then export it in a new DMG file. Temporary directory is then deleted. You can automatically launch this script at the end of your build process.

#!/bin/bash
# Create .dmg file for macOS

# Adapt these variables to your needs
APP_VERS="1.0"
DMG_NAME="MyApp_v${APP_VERS}_macos"
OUTPUT_DMG_DIR="path_to_output_dmg_file"
APP_FILE="path_to_my_app/MyApp.app"
OTHER_FILES_TO_INCLUDE="path_to_other_files"


# The directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# The temp directory used, within $DIR
WORK_DIR=`mktemp -d "${DIR}/tmp"`

# Check if tmp dir was created
if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then
    echo "Could not create temp dir"
    exit 1
fi

# Function to deletes the temp directory
function cleanup {
    rm -rf "${WORK_DIR}"
    #echo "Deleted temp working directory ${WORK_DIR}"
}

# Register the cleanup function to be called on the EXIT signal
trap cleanup EXIT

# Copy application on temp dir
cp -R "${APP_FILE}" "${WORK_DIR}"
# Copy other files without hidden files
rsync -a --exclude=".*" "${OTHER_FILES_TO_INCLUDE}" "${WORK_DIR}"

# Create .dmg
hdiutil create -volname "${DMG_NAME}" -srcfolder "${WORK_DIR}" -ov -format UDZO "${OUTPUT_DMG_DIR}/${DMG_NAME}.dmg"
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.