Skip to content

Instantly share code, notes, and snippets.

@dictav
Last active December 17, 2015 16:59
Show Gist options
  • Save dictav/5643106 to your computer and use it in GitHub Desktop.
Save dictav/5643106 to your computer and use it in GitHub Desktop.
auto increment CFBundleVersion in Xcode project
InfoPlist="${SRCROOT}/${PROJECT_NAME}/${PRODUCT_NAME}-Info.plist"
bn=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${InfoPlist}`
IFS='.'
arr=[]
arr=($bn)
last_num=$((${#arr[*]}-1))
echo $last_num
arr[$last_num]=$((arr[$last_num]+1))
bn="${arr[*]}"
IFS=''
`/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${bn}" ${InfoPlist}`
if test $CONFIGURATION != "TestFlight"; then
exit
fi
echo "Increment build number"
InfoPlist="${SRCROOT}/${PROJECT_NAME}/${PRODUCT_NAME}-Info.plist"
bn=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${InfoPlist}`
IFS_BACKUP=$IFS
IFS='.'
arr=[]
arr=($bn)
arr[0]=$((arr[0]+1))
arr[1]=`date "+%Y%m%d"`
bn="${arr[*]}"
IFS=$IFS_BACKUP
`/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${bn}" ${InfoPlist}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment