Skip to content

Instantly share code, notes, and snippets.

@sascha
Last active September 7, 2016 06:56
Show Gist options
  • Save sascha/5398750 to your computer and use it in GitHub Desktop.
Save sascha/5398750 to your computer and use it in GitHub Desktop.
Xcode build script to automatically bump the build number and convert it to hexadecimal
# 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