创建 DMG 文件

发布于 2024-07-30 11:43:39 字数 103 浏览 3 评论 0原文

我正在 Cocoa 中开发一个应用程序。 我需要创建一个 DMG 文件来安装我的应用程序,例如 Adium(它提供了一个很好的 UI 来将应用程序文件拖到应用程序文件夹)。 有这个工具吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

·深蓝 2024-08-06 11:43:39

如果您有一个用户可能会复制到应用程序目录的文件,那么“支持互联网”的磁盘映像是一个不错的选择。 当您使用 Safari 下载一个(我知道,不是每个人都使用 Safari)时,它会自动安装它,将内容复制到下载位置,然后卸载 DMG 并将其移至垃圾箱。 该应用程序不会自动转到“应用程序”,但它位于用户的硬盘上,他们不必担心摆弄磁盘映像。

磁盘映像可以通过单个终端命令启用互联网:

hdiutil internet-enable -yes "MyDiskImage.dmg"

这应该适用于任何 DMG 文件。 如果您希望用户看到您漂亮的背景,您可能不想这样做。 然而,对于简单的有效负载来说,这是一个不错的方法。 (当然,无论如何,有些人更愿意为此类部署创建 ZIP 文件。)


我发现手动创建 DMG 可能很痛苦。 实际上,您可以在 Xcode 项目中自动创建简单的 DMG。 只需创建一个 Shell 脚本目标(项目 → 新目标...)并使用 hdiutil。 该命令看起来像这样(替换正确的名称和目录):

hdiutil create -fs HFS+ -volname "MyApp 1.0" -srcfolder \
"/directory/with/contents/to/package/" "~/Desktop/MyApp-1.0.dmg"`

您需要将要包含在磁盘映像中的所有内容放在一个目录中,但如果您不害怕使用 在终端中 cp ,这很容易做到。

如果您想查看示例,我自己在 CHDataStructures.framework 中使用了这种方法。 如果您签出代码并在 Xcode 中打开,部署目标中的第二个脚本将创建 DMG。

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.

依 靠 2024-08-06 11:43:39

磁盘实用程序(位于“应用程序\实用程序”中)

转到文件 > 新建 > 来自文件夹的磁盘映像,然后选择要为其创建映像的文件夹。 生成的 .dmg 将复制您用于制作图像的文件夹,直至图标的位置。

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.

吝吻 2024-08-06 11:43:39

Nic 博士整理了一个漂亮的 ruby​​ gem,它可以为您完成大部分工作,您只需要提供 xcode 项目和一些图形。 链接位于:

http://drnicwilliams .com/2009/02/03/choctop-packaging-and-deployment-of-cocoa-applications/

这是一个很棒的包,可以处理原本很痛苦的任务...

--
埃文

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

又怨 2024-08-06 11:43:39

因为还没有足够的答案...

我创建了一个读写 DMG,其中包含我想要的布局——背景图像、大小、应用程序图标的快捷方式以及一个代表我的应用程序的空文件夹。 我编写了一个简单的 bash 脚本来制作此 DMG 的副本,安装它,将我的应用程序复制到空文件夹,卸载 DMG,然后将其转换为只读。

但是 DMG Canvas 可以为您完成整个过程,并且还提供了一个命令行工具,您可以使用它在 Xcode 构建中自动执行此过程,因此我真的会推荐它而不是我的解决方案。

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.

魂归处 2024-08-06 11:43:39

Mozilla 构建脚本是一个很好的来源,如果你想编写你的自己的脚本。 使用 pkg-dmg 您可以自定义背景图像、卷名称、添加许可证、图标等。示例:

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

问题是创建完美的 .DS_Store。 对于简单的情况,您可以创建 .DS_Store 来自定义 Finder 中装载的 dmg 卷(显示视图选项)。 您需要创建一个可写映像,对其进行自定义,卸载(以提交更改),最后再次装载以将生成的 .DS_Store 复制为 MegaFinderCustomizedDS_Store(如其所示)上面的示例)

如果您的应用程序支持 Leopard,我建议使用 DMG Canvas 来管理整个过程或至少获取.DS_Store。 它也有一个命令行工具。

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.

暮倦 2024-08-06 11:43:39

作为自动构建步骤执行此操作的最佳方法是创建一个完全符合您想要的效果的 template.dmg(使用 finder/diskutility 等,但不执行压缩它的最后一步),然后在构建脚本中:

  1. 使用 hdiutil附加图像
  2. 使用 cp 等将应用程序复制到已安装的图像中
  3. hdiutil 分离
  4. 压缩图像: hdiutil Convert "in.dmg" -quiet -format UDZO -imagekey zlib-level=9 -o "MyApp-0.3.dmg"

有一个makefile 位于 https://github.com/remko/fancy-dmg/ ,包含以下步骤。

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:

  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.

虚拟世界 2024-08-06 11:43:39

MacBreak Dev 做了一个关于使用 Automator 工作流程创建 DMG 文件的精彩小截屏视频。 让事情变得非常简单、非常快捷,您可以为您的 DMG 定制背景。 您可以在以下位置查看:
http://www.pixelcorps.tv/mbkd_010

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

獨角戲 2024-08-06 11:43:39

您可以使用 DropDMG 设置带有背景图片、Applications 文件夹的符号链接、您的然后,当您需要制作 .dmg 文件时,您只需将应用程序拖到 DropDMG 上(或通过 AppleScript 或 dropdmg 命令行工具编写脚本),然后让它一步构建磁盘映像。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文