我正在创建一个 dmg 文件并在使用 icns 和 png 文件时出现以下错误。
这是命令:
DeRez -only icns resources/test.icns > icns.rsrc
错误:
/Applications/Xcode.app/Contents/Developer/usr/bin/DeRez - 打开资源文件“resources/test.icns”期间的 SysError -39
Mac OS 版本:macOS mojave 10.14.2
请建议。
刚才也遇到了这个问题,并注意到这个问题没有得到解答,尽管它相当简单。
显然错误 -39 意味着end of file
,我假设这意味着它无法找到预期数据的有效部分。我猜你(像我一样)曾经sips -i someicon.icns
将文件的图标设置为自身?你应该得到一个错误--addIcon is no longer supported
,这对我来说意味着它实际上并没有设置图标。因此,随后的DeRez
调用.rsrc
将失败。
我不想安装任何额外的东西,但幸运的是我在这里找到了另一个答案,似乎只使用了标准的 Xcode 和/或 macOS 工具。在我的情况下,我试图设置一个 AppleScript 导出的.app
图标,但实际的转换部分应该是相同的。
因此,从文件.png
到实际图标的所有步骤.app
:
cd /some/application/dir/some.app/Contents/Resources
cp /some/assets/dir/myicon.png ./
# Convert png to icns
# Keep in mind that sips can allegedly only handle 256x256, 512x512 and 1024x1024 PNGs for this
# Otherwise you need to do something like the following first:
# sips -z 256 256 myicon.png --out myicon_resized.png
# Then check if it came out good and run:
# mv -f myicon_resized.png myicon.png
# Now let's actually convert it and remove the png as it's no longer needed
sips -s format icns myicon.png --out myicon.icns
rm -fv myicon.png
# Apparently you can also specify commands of some sort in .rsrc files (this is the part I needed from the other SO answer)
# This is used in place of DeRez
echo "read 'icns' (-16455) \"myicon.icns\";" > myicon.rsrc
# Now just use Rez to append it to the special icon file in the root of the .app dir
Rez -append myicon.rsrc -o $'../../Icon\r'
# Write the metadata indicating we want to use the Icon\r file for the app's icon
# I could just use ../../ for the path but I like to be explicit
SetFile -a C ../../../some.app
# Also hide said file from Finder views
SetFile -a V $'../../Icon\r'
我没有尝试为.dmg
文件设置自定义图标,但我想你已经知道如何“应用”.rsrc
它。=]