Take the 2-minute tour ×

Is there a way, in Xcode, to run a bash script in a build phase, only when I "Build & Run" and not in all other occasions?

Actually, what I would like to do, is to write a script to update the build number every time I build and run a new version on the device.

share|improve this question
Only when you Build & Run, or also when you just run? –  zneak Feb 20 '11 at 17:14
Please, see the edited question. –  massimoksi Feb 20 '11 at 22:06
Your question is still unclear. 'Build & Run' as opposed to what, exactly? Just 'Build'? –  millenomi Feb 20 '11 at 22:17
add comment

1 Answer

up vote 1 down vote accepted

Xcode does not tell your script why it's building — that is, if it's going to run the app afterwards or not —; only that it is building. Also note that selecting 'Run' as opposed to 'Build & Run' does not run scripts in Run Script phases.

If you build in other occasions, you can pass build settings to xcodebuild (if building from the command line) or by selecting a different build configuration (if building from the Xcode application), which you can refer to in your build scripts as environment variables. For example:

    # increment build number

(This script uses the CONFIGURATION built-in build setting, but you can create custom build settings if needed.)

share|improve this answer
add comment

Your Answer


