85

I've made my first Qt application for Mac OS X. Now I want to create nice .dmg file that will allow user to easily install it. I am thinking about something like firefox has (see the picture): enter image description here

I am completly new to this, so I don't even know where to start.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
xx77aBs
  • 4,678
  • 9
  • 53
  • 77
  • 2
    Maybe this can help you http://stackoverflow.com/questions/96882/how-do-i-create-a-nice-looking-dmg-for-mac-os-x-using-command-line-tools – Roger Lindsjö Dec 30 '11 at 13:57
  • I don't really need it to be automated, I would prefer something easier to get me started ;) – xx77aBs Dec 30 '11 at 17:32
  • 3
    this may be of use: http://el-tramo.be/guides/fancy-dmg/ – Mike K Dec 30 '11 at 23:40
  • @MikeK: You should post this as answer, I will accept it, it is just what I was looking for ;) – xx77aBs Dec 31 '11 at 10:48
  • You can check [this tutorial](https://web.archive.org/web/20140927083340/http://codevarium.gameka.com.br/how-to-create-your-own-beautiful-dmg-files). It shows step-by-step you how to create beautiful DMGs only by using iDMG (which is a free software), Finder and a terminal. Its quite easy. – Igor Augusto Jan 08 '12 at 03:42

6 Answers6

95

Bringing this question up to date by providing this answer.

appdmg is a simple, easy-to-use, open-source command line program that creates dmg-files from a simple json specification. Take a look at the readme at the official website:

https://github.com/LinusU/node-appdmg

Quick example:

  1. Install appdmg

    npm install -g appdmg
    
  2. Write a json file (spec.json)

    {
      "title": "Test Title",
      "background": "background.png",
      "icon-size": 80,
      "contents": [
        { "x": 192, "y": 344, "type": "file", "path": "TestApp.app" },
        { "x": 448, "y": 344, "type": "link", "path": "/Applications" }
      ]
    }
    
  3. Run program

    appdmg spec.json test.dmg
    

(disclaimer. I'm the creator of appdmg)

Linus Unnebäck
  • 23,234
  • 15
  • 74
  • 89
  • Compared to other solutions, this is amazingly simple. – Aeolun Oct 31 '14 at 00:33
  • 1
    Yay, Linus way to go. Uppskattar det. – Prof. Falken Nov 16 '14 at 00:33
  • Any chance to have the compiled binary for OSX 10.6.8? I don't know how to compile your sources... (not much of an apple guy here...) – Mark Miles Feb 06 '15 at 16:53
  • 4
    @MarkMiles most of the code is written in Javascript and thus isn't complied. Npm will take care of compiling all the source files (C, Objective-C) that's necessary. The easiest way to get everything running is 1) Install brew (http://brew.sh) 2) Install Node.js (`brew install node`) which also bundles `npm`. 3) Follow the "Quick example" in the answer – Linus Unnebäck Feb 07 '15 at 12:51
  • @Lothar I think that it would be great to package appdmg as a binary for easy distribution, but the use case I had already included a nodejs environment. But if you think that this could be done in a "simple shell script" then I dare you to try. Have a look at the code, it isn't too trivial. There is a reason that we have other programming languages besides shell scripts. – Linus Unnebäck Apr 13 '15 at 08:30
  • @jr.root.cs No problem, it's always great to hear that people use and like it :) – Linus Unnebäck Jun 25 '15 at 13:11
  • Hey, nice program! Haven't even used it yet but damn it looks perfect! – Mark Lalor Aug 15 '15 at 02:42
  • I have an executable, and it's resources, how do I get a *.app? Is that required to use `appdmg`? – Jonathan Nov 04 '15 at 00:04
  • @JonathanLeaders http://stackoverflow.com/questions/1596945/building-osx-app-bundle – Linus Unnebäck Nov 04 '15 at 06:16
20

It's fairly easy - the basic idea is that you create a blank image using Disk Utility (make it big enough to at least hold your stuff - exact size doesn't matter), open that image using Finder, put your stuff in and arrange it the way you want it (use right-click and Show View Options to set things like icon size or background image). That's almost it - all that remains is to convert that r/w image into a compressed image: eject it and use Convert in Disk Utility to convert it into a compressed image.

Simon Urbanek
  • 13,842
  • 45
  • 45
9

None of the existing answers really did it for me; one answer is manual, and the two other options - iDMG and node-appdmg - both involve applescripting the finder which is not ideal.

The best way to do this as an automatic build step is to create a template.dmg that looks exactly how you want (following the normal instructions, eg Simon Urbanek's answer, but not doing the last step of compressing it), then in your build script:

  1. Use hdiutil to attach the image
  2. Use cp etc to copy the application into the mounted image
  3. hdiutil detach
  4. 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.

JosephH
  • 37,173
  • 19
  • 130
  • 154
  • 2
    We are working to drop AppleScript and bring node-appdmg cross-platform. If you want to follow the work, take a look here: https://github.com/LinusU/node-appdmg/issues?milestone=1&state=open – Linus Unnebäck Dec 04 '13 at 19:41
  • 1
    @LinusUnnebäck That's awesome; thanks for sharing that! Even just removing the applescript dependency would be excellent. – JosephH Dec 04 '13 at 21:20
  • No problem :) we really just need to be able to write our own .DS_Store and all is really figured out, I just need to find time to implement it. (https://github.com/LinusU/node-appdmg/issues/14) – Linus Unnebäck Dec 04 '13 at 21:26
  • .DS_Store is not documented and i'm sure it never will, so it's not the a way out. The template seems to be the only reliable solution. – Lothar Apr 12 '15 at 01:19
3

This script makes DMG generation very easy: https://github.com/andreyvit/create-dmg

Also there is no node dependency :-)

Martin Delille
  • 11,360
  • 15
  • 65
  • 132
2

You can do that with Finder:

  1. Download and unzip this empty DMG file (I'm the one who created and uploaded it)
  2. Resize the DMG file to the appropriate size (the appropriate size is usually its current size plus the size of your .app file). To do this, open the disk utility (if you don't know how to do this, search for disk utility in Launchpad). Then click on "Images" in the menu bar and choose "Resize...". You will get a window to open a file, open the empty DMG file.
  3. Double-click on the DMG file to mount it. A device on the desktop named Untitled should appear. Rename it to the name that you want (you probably want to give it the same name as your program).
  4. Open that device. You should see something like this:

    enter image description here

    If everything is white except the shortcut to the Applications folder, press Cmd+J and a window will be opened. On the bottom of that window, there is a square with the label "Drag image here". Click on that square and an Open dialog will open. In that dialog, press Cmd+Shift+G and type /Volumes/(whatever you called the device in step 3)/.image and select image.png.

    Everything here except the shortcut to the Applications folder is just a background image. You might want to change the background image (which contains the background color and the arrow). To do so, open the file /Volumes/(whatever you called the device in step 3)/.image/image.png in an image editor and edit it to whatever you want. After you've done this, you might need to unmount the device and remount it by opening the DMG file to see the changes. Depending on what you put in the image, you might also need to move the shortcut to the Applications folder around to fit the new background image.

  5. Drag your .app file to the beginning of the arrow in the window where the device from the DMG file is opened so that it looks like this:

    enter image description here

    You might get an error saying that there isn't enough free space. If that's the case, go back to step 2 and resize the DMG file to a larger size.

  6. Unmount the device by clicking on the arrow next to the device name in Finder:

    enter image description here

  7. Convert the DMG file to read only. To do this, open the terminal and type this (replace /path/to/dmg/file by the path to the DMG file and nameOfDmgFile.dmg by the name of the DMG file):

    cd /path/to/dmg/file
    hdiutil convert -format UDZO -o newNameOfDmgFile.dmg nameOfDmgFile.dmg
    

    This will create a new DMG file called newNameOfDmgFile.dmg (or whatever other name you used above), which is the file that you want.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • Why do we need to resize the DMG (as you mentioned in point 2) – Krishna Maru Dec 13 '18 at 05:25
  • @KrishnaMaru It's a long time since I wrote this answer, but if I remember correctly, you would get an error if you try to copy a large file into a DMG that's too small. – Donald Duck Dec 13 '18 at 10:17
0

You could use Disk Utility for this, but if you want a picture in the background, you need some advanced directions.

First, open Disk Utility
Then, Click File > New Image > Blank image.
It will ask you for the size of it and the name.
After that, you can put files into it, and there you go!

NOTE: This was tested on Mac OS Mojave. I don't know about previous versions.

Ivan
  • 3
  • 2