Created
November 2, 2010 19:16
-
-
Save spikegrobstein/660130 to your computer and use it in GitHub Desktop.
Prints the version of a .app or .bundle in OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
## | |
# returns the version of the OSX application that's passed to the script | |
# can determine if you're passing a bundle or an application (.bundle | .app | .component) | |
# and figure out the proper info | |
# | |
# written by Spike Grobstein | |
# spike.grobstein@wmg.com | |
# 2010/11/02 | |
## | |
PLIST_BUDDY="/usr/libexec/PlistBuddy" | |
EXIT_BAD_PATH=2 | |
EXIT_BAD_TYPE=3 | |
APP_PATH=$1 | |
if [[ -z $APP_PATH ]]; then | |
# just print usage and exit | |
echo "Print the version of a .app or .bundle or .component by reading the proper information plist" | |
echo "USAGE: " | |
echo " $0 <path_to_app_or_bundle>" | |
echo "" | |
exit 0 | |
fi | |
if [[ ! -d $APP_PATH ]]; then | |
echo "path does not appear to be the proper type: $APP_PATH" >&2 | |
echo "" >&2 | |
exit $EXIT_BAD_PATH | |
fi | |
# pull the extension off the item... (this should be "app" or "bundle") | |
APP_TYPE=${APP_PATH#*.} # pull the extension off | |
APP_TYPE=${APP_TYPE%/*} # trim a trailing / if there is one | |
if [[ "$APP_TYPE" = "app" ]]; then | |
#this is an app, so we want to load the Info.plist file | |
PLIST_PATH="${APP_PATH}/Contents/Info.plist" | |
$PLIST_BUDDY -c "Print " "$PLIST_PATH" | |
elif [[ "$APP_TYPE" = "bundle" ]]; then | |
# this is a bundle, so let's load version.plist | |
PLIST_PATH="${APP_PATH}/Contents/version.plist" | |
$PLIST_BUDDY -c "Print :CFBundleVersion" "$PLIST_PATH" | |
elif [[ "$APP_TYPE" = "component" ]]; then | |
# this is a bundle, so let's load Info.plist | |
PLIST_PATH="${APP_PATH}/Contents/Info.plist" | |
$PLIST_BUDDY -c "Print :CFBundleShortVersionString" "$PLIST_PATH" | |
else | |
# unknown apptype! | |
echo "This is an unknown apptype ($APP_TYPE)!" >&2 | |
echo "" >&2 | |
exit $EXIT_BAD_TYPE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment