使用命令行工具,如何创建nicelooking DMG的Mac OS X?

使用命令行工具,如何创建nicelooking DMG的Mac OS X?


经过大量的研究,我得到了这个答案,我将它作为我自己问题的答案,供参考:

  1. 确保"启用辅助设备访问"在系统首选项>> 通用访问中被选中。 为AppleScript工作需要它。 在这里更改( 它在 Mac OS X 服务器 10.4上不起作用) 之后你可能必须重新启动。

  2. 创建一个 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来完成该操作:

    1. 
      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
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值