如何从 shell 脚本读取 plist 信息(bundle id)
我想编写一个脚本,可以从应用程序的 Info.plist 中读取捆绑标识符等信息或版本号。 Xcode 似乎没有在其环境变量中提供该信息。还有其他方法可以让它们进入 sh/bash 吗?
I'd like to write a script that can read info like Bundle Identifier or maybe version number from the Info.plist of the app. Xcode doesn't seem to give that information in it's environment variables. Is there any other way to get them in sh/bash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
defaults
命令可以读取/写入任何 plist 文件,只需给它一个减去.plist
扩展名的路径:这会直接提取
CFBundleIdentifier
值来自应用程序包的Info.plist
文件。默认值也适用于二进制 plist,无需任何额外的步骤。
The
defaults
command can read/write to any plist file, just give it a path minus the.plist
extension:This pulls the
CFBundleIdentifier
value directly from the application bundle'sInfo.plist
file.Defaults also works with binary plists without any extra steps.
使用 PlistBuddy(Apple 的一个应用程序),可以将字符串分配给 var,如下所示:
如果您在“运行脚本”构建阶段运行此脚本,则其中 BUILD_ROOT 和 INFOPLIST_PATH 是 Xcode 设置的变量。
Using PlistBuddy, an app by Apple it is possible to assign the string to var like this:
Where BUILD_ROOT and INFOPLIST_PATH are variables set by Xcode if you run this script in a "Run Script" build phase.
这个命令对我有用:
This command worked for me:
您可以直接从构建的产品中读取文件。但是,如果您在编辑器中查看 info.plist 文件本身,您将看到 shell 变量本身。例如,Bundle ID 具有以下 shell 命令:
您可以在 Xcode 运行且应该填充的任何 shell 脚本中调用
${PRODUCT_NAME:rfc1034identifier}
。You can just read the file directly from the built product. However, if you look at the info.plist file itself in the editor you will see the shell variables themselves. E.g. the Bundle ID is has the following shell command:
You can call
${PRODUCT_NAME:rfc1034identifier}
in any shell script that Xcode runs and it should populate.Mac 上安装了一个名为 PlistBuddy 的命令行程序,可以读取/写入 plist 中的值。在终端中输入“man PlistBuddy”以获取更多信息。
There is a command line program installed on the Mac called PlistBuddy that can read/write values in a plist. Type 'man PlistBuddy' in Terminal to get more info.