如何从 shell 脚本读取 plist 信息(bundle id)

发布于 2024-10-05 06:50:37 字数 100 浏览 0 评论 0原文

我想编写一个脚本,可以从应用程序的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

生寂 2024-10-12 06:50:37

defaults 命令可以读取/写入任何 plist 文件,只需给它一个减去 .plist 扩展名的路径:

$ defaults read /Applications/Preview.app/Contents/Info CFBundleIdentifier

com.apple.Preview

这会直接提取 CFBundleIdentifier 值来自应用程序包的 Info.plist 文件。

默认值也适用于二进制 plist,无需任何额外的步骤。

The defaults command can read/write to any plist file, just give it a path minus the .plist extension:

$ defaults read /Applications/Preview.app/Contents/Info CFBundleIdentifier

com.apple.Preview

This pulls the CFBundleIdentifier value directly from the application bundle's Info.plist file.

Defaults also works with binary plists without any extra steps.

万水千山粽是情ミ 2024-10-12 06:50:37

使用 PlistBuddy(Apple 的一个应用程序),可以将字符串分配给 var,如下所示:

#!/bin/sh   
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "${BUILD_ROOT}/${INFOPLIST_PATH}")

如果您在“运行脚本”构建阶段运行此脚本,则其中 BUILD_ROOT 和 INFOPLIST_PATH 是 Xcode 设置的变量。

Using PlistBuddy, an app by Apple it is possible to assign the string to var like this:

#!/bin/sh   
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "${BUILD_ROOT}/${INFOPLIST_PATH}")

Where BUILD_ROOT and INFOPLIST_PATH are variables set by Xcode if you run this script in a "Run Script" build phase.

明明#如月 2024-10-12 06:50:37

这个命令对我有用:

/usr/libexec/PlistBuddy -c 'print ":CFBundleIdentifier"' Info.plist

This command worked for me:

/usr/libexec/PlistBuddy -c 'print ":CFBundleIdentifier"' Info.plist
旧时模样 2024-10-12 06:50:37

您可以直接从构建的产品中读取文件。但是,如果您在编辑器中查看 info.plist 文件本身,您将看到 shell 变量本身。例如,Bundle ID 具有以下 shell 命令:

com.yourcompany.${PRODUCT_NAME:rfc1034identifier}

您可以在 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:

com.yourcompany.${PRODUCT_NAME:rfc1034identifier}

You can call ${PRODUCT_NAME:rfc1034identifier} in any shell script that Xcode runs and it should populate.

も让我眼熟你 2024-10-12 06:50:37

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文