How can I programmatically add a run script build phase to an Xcode project?

For anyone looking for the easy way to do this, there is a great python library that lets you mod all types of things in the .pbxproj file. You can check it out here: https://github.com/kronenthaler/mod-pbxproj.

Now to add a run script build phase you can write a simple python script like:

from pbxproj import XcodeProject
import sys

project = XcodeProject.load('path/to/my-project.xcodeproj/project.pbxproj')
project.add_run_script('bash my_run_script.sh')
project.save()

Now just run the python script and you should be good to go.


The possibly easiest solution is to add a Run Script Phase to the other Project which defines a command line executing a script which resides as a particular file in some known location.

The first project then may have a Run Script Phase, or execute a program which creates or modifies this script file. When the other project starts, it starts the Run Script Phase and - voilà - executes whatever has been defined.