DNB5brims
DNB5brims

Reputation: 30558

Is this possible to run a python script before Xcode doing compiling?

I am using Xcode to develop application. But I include some test files, and I would like to keep a reference timestamp while I do compiling. Is this possible for me to do some scripting before I start compiling the programme? Of course, I can manually run the script before I compiling, but I would like to do it in one step, and recommend? Thanks.

Upvotes: 7

Views: 6692

Answers (3)

Mete
Mete

Reputation: 5625

Just to clarify a little, since the above answers did help me out eventually but were kind of confusing at first:

After you create a new Run Script in your Build Phases:

  1. Use shell = /usr/bin/python, if what you put in the script text box is pure python code.

  2. Use shell = /bin/sh if you want to run a python file, and include the full command to launch the script e.g.:

enter image description here

Upvotes: 6

NachoChip
NachoChip

Reputation: 307

  1. Project File -> Build Phases -> Add Build Phase (Bottom right) -> Add Run Script
  2. Drag the new build phase into the correct order
  3. Under Shell -> /bin/sh
  4. Then in the text box, fill up something like "/usr/bin/python /Users/me/test.py"

Upvotes: 6

mergesort
mergesort

Reputation: 5187

You need to add a build phase. Go to the project file, Build Phases, click Editor on the tool bar menu, add Build Phase, Add Run Script... You can select and drag the script to put it before/after anything.

Then the shell should be /usr/bin/python, then you can type in your script below. The script will run every time you build.

Upvotes: 9

Related Questions