我已经为Mac OS X创建了我的第一个Qt应用程序。现在我想创建漂亮的.dmg文件,让用户可以轻松安装它。我正在考虑类似Firefox的东西(见图片):
![输入图像说明](https://istack.dev59.com/M8P9e.webp)
我完全不知道从哪里开始,因为这是我第一次这样做。
我已经为Mac OS X创建了我的第一个Qt应用程序。现在我想创建漂亮的.dmg文件,让用户可以轻松安装它。我正在考虑类似Firefox的东西(见图片):
我完全不知道从哪里开始,因为这是我第一次这样做。
通过提供这个答案来更新这个问题。
appdmg
是一个简单易用的开源命令行程序,它可以根据一个简单的json规范创建dmg文件。请访问官方网站上的自述文件:
https://github.com/LinusU/node-appdmg
快速示例:
安装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的创作者)brew install node
),它也包含了npm
。3)按照答案中的“快速示例”操作即可。 - Linus Unnebäck这很容易 - 基本思路是使用Disk Utility创建一个空白的图像(使其足够大以至少容纳您的资料 - 精确大小并不重要),使用Finder打开该图像,将您的资料放入并按照所需方式排列(使用右键单击和Show View Options设置图标大小或背景图像等)。就差不多了 - 剩下的就是将该可读写(r/w)图像转换为压缩图像:弹出它并使用Disk Utility中的Convert将其转换为压缩图像。
对我来说,现有的答案都不是很合适;一个答案是手动的,另外两个选项 - iDMG和node-appdmg - 都涉及到编写苹果脚本,这不是理想的选择。
作为自动构建步骤,最好的方法是创建一个 template.dmg,它看起来完全符合您的要求(按照正常的说明,例如Simon Urbanek的答案,但不执行压缩的最后一步),然后在您的构建脚本中:
在https://github.com/remko/fancy-dmg/上有一个包含这些步骤的makefile。
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.Untitled
should appear. Rename it to the name that you want (you probably want to give it the same name as your program).Open that device. You should see something like this:
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.
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:
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.
Unmount the device by clicking on the arrow next to the device name in Finder:
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.