为Mac OS X创建漂亮的dmg“安装程序”

86

我已经为Mac OS X创建了我的第一个Qt应用程序。现在我想创建漂亮的.dmg文件,让用户可以轻松安装它。我正在考虑类似Firefox的东西(见图片):

输入图像说明

我完全不知道从哪里开始,因为这是我第一次这样做。


2
也许这可以帮助你:https://dev59.com/u3VD5IYBdhLWcg3wE3Xz - Roger Lindsjö
我并不需要自动化,我更希望有些更容易上手的东西来帮助我开始。 - xx77aBs
3
这可能会有用:http://el-tramo.be/guides/fancy-dmg/ - Mike K
@MikeK:你应该把这个发表为答案,我会接受它,这正是我在寻找的 ;) - xx77aBs
您可以查看此教程。 它详细展示了如何通过使用免费软件iDMG,Finder和终端逐步创建漂亮的DMG文件。 这相当容易。 - Igor Augusto
6个回答

95

通过提供这个答案来更新这个问题。

appdmg是一个简单易用的开源命令行程序,它可以根据一个简单的json规范创建dmg文件。请访问官方网站上的自述文件:

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

快速示例:

  1. 安装appdmg

npm install -g appdmg
  • 编写一个 JSON 文件 (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" }
      ]
    }
    
  • 运行程序

    appdmg spec.json test.dmg
    
    (声明:我是appdmg的创作者)

  • 1
    耶,Linus 做得好。感激不尽。 - Prof. Falken
    4
    @MarkMiles 大部分的代码都是用JavaScript编写的,因此不需要编译。Npm会负责编译所有必要的源文件(C、Objective-C)。让一切运行起来最简单的方法是:1)安装brew(http://brew.sh) 2)安装Node.js(brew install node),它也包含了npm。3)按照答案中的“快速示例”操作即可。 - Linus Unnebäck
    嘿,不错的程序!虽然还没有使用过,但看起来完美无缺! - Mark Lalor
    @JonathanLeaders https://dev59.com/fnI-5IYBdhLWcg3w9tdw - Linus Unnebäck
    天啊,抱歉发牢骚,但我得分享一下我的痛苦。“安装brew来安装node来安装appdmg”。天哪!一个普通人怎么能知道怎么做这一切呢?我放弃尝试安装所有这些了。到处的指导都行不通。这东西根本就不工作。 - undefined
    显示剩余5条评论

    20

    这很容易 - 基本思路是使用Disk Utility创建一个空白的图像(使其足够大以至少容纳您的资料 - 精确大小并不重要),使用Finder打开该图像,将您的资料放入并按照所需方式排列(使用右键单击和Show View Options设置图标大小或背景图像等)。就差不多了 - 剩下的就是将该可读写(r/w)图像转换为压缩图像:弹出它并使用Disk Utility中的Convert将其转换为压缩图像。


    9

    对我来说,现有的答案都不是很合适;一个答案是手动的,另外两个选项 - iDMG和node-appdmg - 都涉及到编写苹果脚本,这不是理想的选择。

    作为自动构建步骤,最好的方法是创建一个 template.dmg,它看起来完全符合您的要求(按照正常的说明,例如Simon Urbanek的答案,但不执行压缩的最后一步),然后在您的构建脚本中:

    1. 使用hdiutil附加映像
    2. 使用cp等命令将应用程序复制到已挂载的映像中
    3. hdiutil分离
    4. 压缩映像:hdiutil convert“in.dmg”-quiet -format UDZO -imagekey zlib-level = 9 -o“MyApp-0.3.dmg”

    https://github.com/remko/fancy-dmg/上有一个包含这些步骤的makefile。


    2
    我们正在努力放弃AppleScript并引入跨平台的node-appdmg。如果您想关注这项工作,请在此处查看:https://github.com/LinusU/node-appdmg/issues?milestone=1&state=open - Linus Unnebäck
    1
    @LinusUnnebäck 非常棒,感谢分享!即使只是移除 AppleScript 依赖也会非常好。 - JosephH
    没问题 :) 我们实际上只需要能够编写自己的.DS_Store文件,一切都已经想好了,我只需要找时间来实现它。 (https://github.com/LinusU/node-appdmg/issues/14) - Linus Unnebäck
    .DS_Store没有文档说明,我相信它永远不会有,所以这不是一个出路。模板似乎是唯一可靠的解决方案。 - Lothar

    3

    2
    您可以使用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.


    为什么需要调整DMG的大小(正如您在第2点中提到的)? - Krishna Maru
    @KrishnaMaru 自从我写下这个答案已经很长时间了,但如果我没记错的话,如果你试图将一个大文件复制到一个太小的DMG中,你会收到一个错误。 - Donald Duck

    0
    你可以使用磁盘工具来完成这个任务,但如果你想要在背景中放置一张图片,你需要一些高级的指导。
    首先,打开磁盘工具。 然后,点击文件 > 新建映像 > 空白映像。 它会要求你输入大小和名称。 之后,你就可以把文件放进去了,完成!
    注意:这是在Mac OS Mojave上测试过的。我不知道之前的版本。

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接