使用命令行工具,如何创建nicelooking DMG的Mac OS X?
经过大量的研究,我得到了这个答案,我将它作为我自己问题的答案,供参考:
-
确保"启用辅助设备访问"在系统首选项>> 通用访问中被选中。 为AppleScript工作需要它。 在这里更改( 它在 Mac OS X 服务器 10.4上不起作用) 之后你可能必须重新启动。
-
创建一个 R/w DMG 。它必须大于结果。 在本例中,bash变量"大小"包含了Kb的大小,"源"bash变量中的文件夹内容将被复制到 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
挂载磁盘映像,并存储设备名称( 你可能希望在这里操作之后几秒钟内使用睡眠):
device=$(hdiutil attach -readwrite -noverify -noautoopen"pack.temp.dmg" | egrep '^/dev/' | sed 1q | awk '{print $1}')
将背景图片( 以PNG格式格式) 存储在DMG中名为"。背景"的文件夹中,并将它的名称存储在"backgroundpicturename"变量中。
使用AppleScript设置视觉样式(. app的名称必须在bash变量中"applicationname"根据需要对其他属性使用变量):
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
通过正确设置权限,压缩并释放该DMG来完成该操作:
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
在 Snow Leopard 上,上面的applescript不会正确设置 icon 位置- 它似乎是一个雪花 Leopard Bug 。 一个解决办法是在设置图标后调用 close/打开,i.e.:
.. set position of item"'${applicationName}'" of container window to {100, 100} set position of item"Applications" of container window to {375, 100} close open