Xcode: Running a script before every build that modifies source code directly

Solution 1:

Every technique mentioned so far is an overkill. Reproducing steve kim's comment for visibility:

In the build phases tab, simply drag the "Run Script" step to a higher location (e.g. before "Compile Sources").

Tested on Xcode 6

Solution 2:

This solution is probably outdated. See the higher voted answer instead; I no longer actively use Xcode and am not qualified to vet a solution.


Use "External Target":

  1. Select "Project" > "New Target..." from the menu
  2. Select "Mac OS X" > "Other" > "External Target" and add it to your project
  3. Open its settings and fill in your script setup
  4. Open the "General" tab of the main target's settings and add the new target as it's direct dependency

Now the new "External Target" runs before the main target even starts gathering dependency information, so that any changes made during the script execution should be included in the build.