Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 363
Dimitris Avatar asked Dec 01 '10 19:12

Dimitris


2 Answers

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.

like image 129
joemaller Avatar answered Oct 02 '22 07:10

joemaller


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.

like image 33
Dimitris Avatar answered Oct 02 '22 08:10

Dimitris