如何以编程方式(最好是bash)将图标添加到dmg?
我有一个bash脚本,为我的node.js应用程序创建一个.dmg。但是,Finder中出现的.dmg图标是标准磁盘图标。我需要它与应用程序的图标相同。如何以编程方式(最好是bash)将图标添加到dmg?
我知道我可以cmd+I
在我的.app在Finder,复制图标,和cmd+I
我的.dmg和粘贴。但是我希望我的构建过程能够完全自动化。我不想为此使用第三方工具,因为我已经在我的bash脚本中使用了代码签名和本地化。
我曾尝试将我的icns作为.VolumeIcon.icns
复制到我的dmg的根目录中。它没有效果。我也尝试过SetFile -a C "path/to/dmg/.VolumeIcon.icns"
。这也没有任何效果,并且man SetFile
表示它已被弃用。我正在建立在macOS Sierra 10.12.6上。
由于简单的复制和粘贴工作,必须有一种方法来编程!但是,如何?
更新
这部分工作:
hdiutil create -srcfolder "my/build/dir" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -volname MyAppName -ov -attach "my/output/dir/MyAppName.uncompressed.dmg"
SetFile -c icnC "/Volumes/MyAppName/.VolumeIcon.icns"
SetFile -a C "/Volumes/MyAppName"
它不.dmg文件本身的图标关联,但如果我双击.dmg文件,在Finder窗口显示有我的图标。
虽然主要需要的是.dmg文件本身。当有人下载我的.dmg文件时,我需要坐在Downloads文件夹中的.dmg文件具有我的图标,而不是标准磁盘图标。如上所述,这很容易手动,但我怎样才能从一个bash脚本或AppleScript中做到这一点?
比方说,你有像这样的
和它保存为:cc.png。做以下
cp cc.png cc_copy.png
sips -i cc_copy.png
DeRez -only icns cc_copy.png > icns.rsrc
mkdir some_installer
hdiutil create -volname installer -srcfolder ./some_installer -ov -format UDZO my_app.dmg
Rez -append icns.rsrc -o my_app.dmg
SetFile -a C my_app.dmg
,你将结束:
是你在找什么?
更新:
应该ICNS工作,以及
cp /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/macOS.icns .
cp macOS.icns macOS_copy.icns
sips -i macOS_copy.icns
DeRez -only icns macOS_copy.icns > icns.rsrc
hdiutil create -volname installer -srcfolder ./some_installer -ov -format UDZO my_app.dmg
Rez -append icns.rsrc -o my_app.dmg
SetFile -a C my_app.dmg
谢谢,我想这正是我正在寻找的,但我实际上是从一个图标开始,而不是一个.png。有没有办法做到这一点从一个图标开始,或者我需要先将其转换为.png? –
工作很好,谢谢!我唯一关心的是来自Sierra 10.12.6终端的手册页,他说:“支持碳开发的工具,包括/ usr/bin/SetFile,已经被Xcode 6弃用了。” DeRez和Rez也是如此。有没有不推荐使用的另一种方法? –
说实话,我从来没有使用过其他任何东西,所以,我不知道其他使用dmg文件的方式。实际上,我也使用Rez将许可证声明添加到dmg文件中:http://www.owsiak.org/?p=700 – mko
您可能会在SetFile命令之前缺少一个步骤。尝试这个。
SetFile -c icnC "path/to/dmg/.VolumeIcon.icns"
SetFile -a C "path/to/dmg"
点击此处了解详情:http://docplayer.net/20858155-How-to-create-a-yosemite-installer.html
谢谢 - 这会将图标放入双击安装程序时打开的Finder窗口。不是我想要问的,但也有帮助。 –
看看这里:http://www.owsiak.org/?p=683 - 我指的是相当古老,但仍然非常好的书。不幸的是,它可以通过SafariBooksOnline - 付费服务。 – mko
@mko我找到了背景图片的说明,但没有设置Finder中为dmg文件本身显示的图标。 –