The following are the steps I would like to have:
There's a command line utility called xcodebuild (man page here) which may work better for what you want to accomplish.
xcodebuild