Skip to content

Instantly share code, notes, and snippets.

@alokc83
Forked from sascha/bump_build_number.sh
Last active January 2, 2016 12:59
Show Gist options
  • Save alokc83/8307291 to your computer and use it in GitHub Desktop.
Save alokc83/8307291 to your computer and use it in GitHub Desktop.
# This script is based on the script provided at http://stackoverflow.com/questions/9258344/xcode-better-way-of-incrementing-build-number
# The only difference is, that it uses hexadecimal build numbers instead of decimal ones.
# For instructions on how to use this script, see the link above.
#!/bin/sh
if [ $# -ne 1 ]; then
echo usage: $0 plist-file
exit 1
fi
plist="$1"
dir="$(dirname "$plist")"
# Only increment the build number if source files have changed
if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then
buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist")
if [ -z "$buildnum" ]; then
echo "No build number in $plist"
exit 2
fi
buildnum=`printf "%d" 0x$buildnum`
buildnum=$(expr $buildnum + 1)
buildnum=`printf "%x" $buildnum`
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist"
echo "Incremented build number to $buildnum"
else
echo "Not incrementing build number as source files have not changed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment