Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create DMG file [duplicate]

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?

like image 652
MobX Avatar asked Aug 06 '09 09:08

MobX


People also ask

How do you duplicate files on a Mac?

A keyboard shortcut is also available to duplicate files. Just select an item and press the Command + D keys to duplicate.

How do I duplicate a file?

Go to the location of the document you want to duplicate. Right-click the file, and click Open as copy. A new file opens and is named Copy of Document, Document 2, or similar. In the new file that opens, click the File tab, then click Save As.

Why does my Mac create duplicate files?

Intentional duplicates are files that you've created multiple backups or need to have saved in different folders. But because those files have the same name, any app would see them as unwanted files. Accidental duplicates are files that you've maybe downloaded multiple times or didn't mean to save in various locations.


2 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.

like image 183
Quinn Taylor Avatar answered Oct 14 '22 14:10

Quinn Taylor


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.

like image 45
Amber Avatar answered Oct 14 '22 16:10

Amber