我需要为Mac应用程序创建一个很好的安装程序。我希望它是一个磁盘映像(DMG),具有预定义的大小、布局和背景图像。
我需要在一个脚本中以编程方式做到这一点,将其集成到现有的构建系统中(实际上更多的是一个包系统,因为它只创建安装程序。构建是单独完成的)。
我已经用“hdiutil”完成了DMG的创建,我还没有发现的是如何制作图标布局和指定背景位图。
我需要为Mac应用程序创建一个很好的安装程序。我希望它是一个磁盘映像(DMG),具有预定义的大小、布局和背景图像。
我需要在一个脚本中以编程方式做到这一点,将其集成到现有的构建系统中(实际上更多的是一个包系统,因为它只创建安装程序。构建是单独完成的)。
我已经用“hdiutil”完成了DMG的创建,我还没有发现的是如何制作图标布局和指定背景位图。
当前回答
我找到了这个很棒的mac应用程序来自动化这个过程- http://www.araelium.com/dmgcanvas/ 如果你正在为你的MAC应用程序创建DMG安装程序,你必须看看
其他回答
我使用dmgbuild。
安装:pip3 install dmgbuild 挂载您的卷 创建一个设置文件:
{
"title": "NAME",
"background": "YOUR_BACKGROUND.png",
"format": "UDZO",
"compression-level": 9,
"window": { "position": { "x": 100, "y": 100 },
"size": { "width": 640, "height": 300 } },
"contents": [
{ "x": 140, "y": 165, "type": "file", "path": "/Volumes/YOUR_VOLUME_NAME/YOUR_APP.app" },
{ "x": 480, "y": 165, "type": "link", "path": "/Applications" }
]
}
width值是背景的宽度。 高度值应该是窗口栏的背景高度+ 20。 在终端中:dmgbuild -s settings。. json "YOUR_VOLUME_NAME"输出
通过提供这个答案来更新这个问题。
Appdmg是一个简单、易用的开源命令行程序,可以根据简单的json规范创建dmg文件。看看官方网站的自述:
https://github.com/LinusU/node-appdmg
简单的例子:
安装appdmg 安装-g appdmg 编写一个json文件(spec.json) { "title": "测试标题", “背景”:“background.png”, “icon-size”:80年, “内容”:[ {“x”:192年,“y”:344年,“类型”:“文件”、“路径”:“TestApp。应用"}, {“x”:448年,“y”:344年,“类型”:“链接”,“路径”:“/应用程序”} ] } 运行程序 Appdmg spec.json test.dmg
(免责声明。我是appdmg的创建者)
如果你想设置自定义卷图标,那么使用下面的命令
/*Add a drive icon*/
cp "/Volumes/customIcon.icns" "/Volumes/dmgName/.VolumeIcon.icns"
/*SetFile -c icnC will change the creator of the file to icnC*/
SetFile -c icnC /<your path>/.VolumeIcon.icns
现在创建读/写dmg
/*to set custom icon attribute*/
SetFile -a C /Volumes/dmgName
经过大量的研究,我得出了这个答案,我在这里把它作为我自己的问题的答案,供参考:
Make sure that "Enable access for assistive devices" is checked in System Preferences>>Universal Access. It is required for the AppleScript to work. You may have to reboot after this change (it doesn't work otherwise on Mac OS X Server 10.4). Create a R/W DMG. It must be larger than the result will be. In this example, the bash variable "size" contains the size in Kb and the contents of the folder in the "source" bash variable will be copied into the DMG: hdiutil create -srcfolder "${source}" -volname "${title}" -fs HFS+ \ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${size}k pack.temp.dmg Mount the disk image, and store the device name (you might want to use sleep for a few seconds after this operation): device=$(hdiutil attach -readwrite -noverify -noautoopen "pack.temp.dmg" | \ egrep '^/dev/' | sed 1q | awk '{print $1}') Store the background picture (in PNG format) in a folder called ".background" in the DMG, and store its name in the "backgroundPictureName" variable. Use AppleScript to set the visual styles (name of .app must be in bash variable "applicationName", use variables for the other properties as needed): echo ' tell application "Finder" tell disk "'${title}'" open set current view of container window to icon view set toolbar visible of container window to false set statusbar visible of container window to false set the bounds of container window to {400, 100, 885, 430} set theViewOptions to the icon view options of container window set arrangement of theViewOptions to not arranged set icon size of theViewOptions to 72 set background picture of theViewOptions to file ".background:'${backgroundPictureName}'" make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"} set position of item "'${applicationName}'" of container window to {100, 100} set position of item "Applications" of container window to {375, 100} update without registering applications delay 5 close end tell end tell ' | osascript Finialize the DMG by setting permissions properly, compressing and releasing it: chmod -Rf go-w /Volumes/"${title}" sync sync hdiutil detach ${device} hdiutil convert "/pack.temp.dmg" -format UDZO -imagekey zlib-level=9 -o "${finalDMGName}" rm -f /pack.temp.dmg
在雪豹上,上面的applescript不能正确设置图标的位置-这似乎是一个雪豹bug。一个解决方法是在设置图标后简单地调用close/open,即:
..
set position of item "'${applicationName}'" of container window to {100, 100}
set position of item "Applications" of container window to {375, 100}
close
open
我的应用,DropDMG,是一个简单的方法来创建磁盘图像的背景图片,图标布局,自定义卷图标,和软件许可协议。它可以通过“dropdmg”命令行工具或AppleScript从构建系统中控制。如果需要,图片和许可证RTF文件可以存储在您的版本控制系统下。