Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xrksudy/7f9b5dc7427b02aef3da to your computer and use it in GitHub Desktop.
Save xrksudy/7f9b5dc7427b02aef3da to your computer and use it in GitHub Desktop.

Revisions

  1. @CodeEagle CodeEagle revised this gist Sep 15, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Xcode Team Adding Build Number Shell Script
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    # 1. Select: your Target in Xcode
    # 2. Select: Build Phases Tab
    # 3. Select: Add Build Phase -> Add Run Script
    # 4. Paste code below in to new "Run Script" section
    # 5. Drag the "Run Script" below "Link Binaries With Libraries"
    # 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)

    currentUser="$USER"

    cretePlist() {
  2. @CodeEagle CodeEagle renamed this gist Sep 15, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @CodeEagle CodeEagle created this gist Sep 15, 2015.
    47 changes: 47 additions & 0 deletions sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    currentUser="$USER"

    cretePlist() {
    cat > build.plist <<EOF
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>$currentUser</key>
    <string>1</string>
    <key>users</key>
    <string>$currentUser</string>
    </dict>
    </plist>
    EOF
    }
    [ -f ${PROJECT_DIR}/build.plist ] && echo "Found build.plist" || cretePlist
    users=$(/usr/libexec/PlistBuddy -c "Print users" "${PROJECT_DIR}/build.plist")
    mybuild=$(/usr/libexec/PlistBuddy -c "Print $currentUser" "${PROJECT_DIR}/build.plist")
    alreadyIn=0

    if [[ $users == *"$currentUser"* ]]
    then
    alreadyIn=1
    fi

    if [ ${alreadyIn} -eq 0 ];
    then
    users="$users|$currentUser"
    build=1
    /usr/libexec/PlistBuddy -c "Set :users $users" "${PROJECT_DIR}/build.plist"
    /usr/libexec/PlistBuddy -c "Add :$currentUser string $build" "${PROJECT_DIR}/build.plist"
    else
    mybuild=$(($mybuild + 1))
    /usr/libexec/PlistBuddy -c "Set :$currentUser $mybuild" "${PROJECT_DIR}/build.plist"
    fi


    IFS='|' read -ra ADDR <<< "$users"
    totalBuild=0
    for i in "${ADDR[@]}"; do
    echo "$i"
    memberbuild=$(/usr/libexec/PlistBuddy -c "Print $i" "${PROJECT_DIR}/build.plist")
    totalBuild=$(($totalBuild + $memberbuild))
    done
    echo $totalBuild
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $totalBuild" "${PROJECT_DIR}/${INFOPLIST_FILE}"