Skip to content

Instantly share code, notes, and snippets.

@jmoody
Created October 15, 2015 11:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoody/30f3e071d85419320320 to your computer and use it in GitHub Desktop.
Save jmoody/30f3e071d85419320320 to your computer and use it in GitHub Desktop.
Bash script for extracting CFBundleIdentifier from .app or .ipa (MacOS only)
#!/usr/bin/env bash
function error {
echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
}
function usage {
echo "Usage: bundle-id.sh /path/to/App.{ipa | app}"
}
function ditto_or_exit {
ditto "${1}" "${2}"
if [ "$?" != 0 ]; then
error "Could not copy:"
error " source: ${1}"
error " target: ${2}"
if [ ! -e "${1}" ]; then
error "The source file does not exist"
fi
error "Exiting 1"
exit 1
fi
}
if [ -z "${1}" ]; then
usage
exit 1
fi
FILE="${1}"
if [ ! -e "${FILE}" ]; then
error "File ${FILE} does not exist"
fi
ORIGINAL_DIR="${PWD}"
EXT=`echo "${FILE##*.}" | tr -d '\n'`
if [ "${EXT}" = "app" ]; then
PLIST="${FILE}/Info.plist"
elif [ "${EXT}" = "ipa" ]; then
TMP_DIR=$(mktemp -d -t 'bundle-id-tmpdir')
ditto_or_exit "${FILE}" "${TMP_DIR}"
cd "${TMP_DIR}"
IPA=`basename ${FILE} | tr -d '\n'`
unzip -q "${IPA}"
PLIST=`find ./Payload -maxdepth 2 -type f -name Info.plist -print0`
else
error "Expected a .app or .ipa extention; found ${EXT}"
fi
/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "${PLIST}"
EXIT=$?
if [ -e "${TMP_DIR}" ]; then
rm -rf "${TMP_DIR}"
fi
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment