首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将图标设置为不使用icns和png的dmg文件。

将图标设置为不使用icns和png的dmg文件。
EN

Stack Overflow用户
提问于 2019-02-15 11:18:35
回答 1查看 346关注 0票数 1

我正在创建一个dmg文件,并在使用icns和png文件时得到以下错误。

这里是命令:

代码语言:javascript
复制
DeRez -only icns resources/test.icns > icns.rsrc

错误:

/Applications/Xcode.app/Contents/Developer/usr/bin/DeRez - SysError -39在打开资源文件"resources/test.icns“期间

macOS版本:macOS mojave 10.14.2

请建议一下。

EN

回答 1

Stack Overflow用户

发布于 2021-07-05 18:22:26

刚才也遇到了这个问题,注意到这个问题没有得到回答,尽管它很简单。

显然,错误-39意味着end of file,我假设这意味着它无法找到预期的数据的有效部分。我猜您(像我一样)使用sips -i someicon.icns将文件的图标设置为自己?你应该得到一个错误的--addIcon is no longer supported,对我来说,这意味着它没有真正设置图标。因此,随后的DeRez调用获得一个.rsrc将失败。

我不想安装任何额外的东西,但幸运的是,我发现another answer on here似乎只使用标准的Xcode和/或macOS工具。在我的例子中,我试图设置一个AppleScript导出的.app图标,但是实际的转换部分应该是相同的。

因此,从.png.app文件的实际图标的所有步骤:

代码语言:javascript
复制
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“应用”到它了。=]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54708191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档