title: Batch Build and Archive of iOS apps via Terminal
body: <p>I am trying to simplify the build->archive->submit process for iOS app publishing.
  We have over 50 mobile apps that have nearly identical framework, but with different artwork and configuration settings.</p>
  
  <p>I normally would load each project in xcode 4.2 and build->archive->submit the usual way with the xcode GUI, but we are up over 50 apps now and this process is very tiresome any time we push out an update.</p>
  
  <p>That being said, I am trying to speed up this process with using a shell function.
  I did plenty of research and found that <a href="https://stackoverflow.com/questions/2664885/xcode-build-and-archive-from-command-line">xcodebuild</a> (See Reid's answer) should work, however the Archive option is not working as I get the following error:</p>
  
  <pre><code>unsupported build action 'archive'
  </code></pre>
  
  <p>So I wrote the following:</p>
  
  <pre><code># $1 should be a date like: 2012-07-17
  # $2 should be a time like: 10.31AM
  # $mybase will be the current directory at the time the function was called
  # so make sure to cd into the folder containing the xcode project folders first
  
  function xcodeArchive {
      mkdir ~/Library/Developer/Xcode/Archives/$1
      mybase=$PWD
      for x in `ls`
      do
          mkdir ~/Library/Developer/Xcode/Archives/$1/$x
          mkdir ~/Library/Developer/Xcode/Archives/$1/$x/dSYMs
          mkdir ~/Library/Developer/Xcode/Archives/$1/$x/Products
          mkdir ~/Library/Developer/Xcode/Archives/$1/$x/Products/Applications
          cd $mybase/$x
          xcodebuild
          #read -p "Press [Enter] to continue"
          cd $mybase/$x
          cp $x/$x-Info.plist ~/Library/Developer/Xcode/Archives/$1/$x/Info.plist
          cp -r build/Release-iphoneos/$x.app.dSYM ~/Library/Developer/Xcode/Archives/$1/$x/dSYMs/$x.app.dSYM
          cp -r build/Release-iphoneos/$x.app ~/Library/Developer/Xcode/Archives/$1/$x/Products/Applications/$x.app
          cd ~/Library/Developer/Xcode/Archives/$1/
          mv $x $x\ $1\ $2.xcarchive
          cd $mybase
      done
  }
  export -f xcodeArchive
  </code></pre>
  
  <p>I put this in my .bash_profile and everything runs correctly as I would expect, except I'm not copying the correct "Info.plist" and I can't figure out where to copy it from or how to generate it. So now I am stuck.</p>
  
  <p>Xcode will recognize the archives, but it lists them under "Unknown Schema" and "Unnamed Archive" in the organizer.</p>
  
  <p><strong>Any help regarding now to get the correct Info.plist is greatly appreciated.</strong></p>
  
  <p>I also welcome recommendations on how to improve the script and/or a more efficient way to batch build+archive these iOS apps. </p>
  
  <p><strong><em>Note:</em></strong></p>
  
  <ul>
  <li><p>I am unable to upgrade beyond Xcode 4.2 as that requires (as I understand it) OS X 10.7+ which I am not able to obtain yet (company computer).</p></li>
  <li><p>I am still very much a bash/shell novice, so I apologize for any ugly code/practice above.</p></li>
  <li><p>Also, this is for official app submission, not for ad-hoc or anything like that.</p></li>
  </ul>
  
  <p>Thanks again for your help.</p>