Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Xcode Auto-incrementing Version and Build numbers
# forked from Luke Jernejcic
BUILDNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILDNUM" "${PROJECT_DIR}/${INFOPLIST_FILE}"
# this splits a two-decimal version string, such as "0.45.123", allowing us to replace the latest build number at the 3rd position
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F"." '{print $1 "." $2 ".'$BUILDNUM'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "${PROJECT_DIR}/${INFOPLIST_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment