How to read plist information (bundle id) from a shell script How to read plist information (bundle id) from a shell script xcode xcode

How to read plist information (bundle id) from a shell script


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 CFBundleIdentifiercom.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.


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.


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.