Michael Kaye asked me “how he can he handle things like Localizable.strings and InfoPlist.strings. You can’t have two copies of these files and there is no info.plist setting I can use to target the correct file with a different name. Plus how would one handle different Default.png for each target?” Answer to this question is very simple, you have to write a script which should run before compiling your application.
So in this tutorial I am going to write a Script file which will run before compiling and that script will overrite existing files and only copies required files for that build. If you didnt read first part of this tutorial, then I recommend you to read the first part before you continue reading this tutorial (Same Xcode Project Create Multiple Products for iPhone).
So in this tutorial I am going to handle different Default.png file for both lite and full versions, also I add different background screens for different versions. Out put will look like this
Take the old code which I used in first tutorial (you can grab old code from here). Open it in Xcode and drag two images files in to Xcode (just like we add images to the project), one is Default.png and other one is PakistanFlag.png (In my case both Image are same). Also place images folder anywhere you like, I place it inside my project (Note: please do not drag it in Xcode project)

Open your HelloWorldViewController.xib file and place UIImageView component (320×480 px) and provide “PakistanFlag.png” file as image. Map it to your HelloWorldViewController.h file.
Once we set-up everything for Xcode now its time to write a script for it. As we have two targets files inside Xcode project we have to do these steps for every target (Best solution would be you add a script to one target and then duplicate it). Please follow the following steps to write a script:
- In your project “Group & Files” panel expand “Targets” and right click on “HelloWorld” and select > Add > New Build Phase > New Run Script Build Phase.

- In Script TextArea write script file name with path of the script as well, which in my case is “./runtimeScript”

- Close this window and expand the target “HelloWorld” you will see a “Run Script” folder at the end. Move it to top in hiracry so that it runs before anything else compile.


- Please repeat step 1,2,3 for “HelloWorldLite” target as well. We will be using same script file for both tragets.

- Now its time to write a script for your project. Right click on “Resource” and select >Add > New File. Select “Other” from the panel and then select “Shell Script”. Click Next and give it a name you write in step two (runtimeScript) and do not select any target because we do not want to copy this file in our binary project.




- Open the script file and copy the below code inside of it
#!/bin/tcsh -f echo .runtimeScript: $TARGET_NAME if ($TARGET_NAME == "HelloWorldLite") then cp Images/PakistanFlag-Lite.png PakistanFlag.png cp Images/PakistanFlag-Lite.png Default.png endif if ($TARGET_NAME == "HelloWorld") then cp Images/PakistanFlag-Full.png PakistanFlag.png cp Images/PakistanFlag-Full.png Default.png endif #
Now its all setup. Select different version and see the result. I hope this help you Michael Kaye. You can grab the code from here.
Popularity: 9% [?]






Thank you! You are a star!
It’s interesting to see how to use a script. Though I don’t quite get the reason for it. For my Luckywheel and LuckyWheel Lite I have the same project. The resources specific to Lite I have in a sub folder. Now all I needed to do is assign the regular info.plist and Default.png to the regular target and for the Lite target deselect those and instead select info.plist and Default.png from the sub folder. No scripting necessary. I still use a script though, to cut out only 10 questions per language file for the Lite version.
I tried this in my project, but for some reason, the copy (CpResource command) only executes once every 2 builds.
I downloaded your sample app and the same thing happens.
The build output looks like this:
(For the first build)
====================
.runtimeScript: HelloWorld
====================
(For the second build)
====================
.runtimeScript: HelloWorld
CpResource build/Debug-iphonesimulator/HelloWorld.app/Default.png Default.png
cd /Users/kevin/Downloads/HelloWorld
setenv PATH “/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks /Users/kevin/Downloads/HelloWorld/Default.png /Users/kevin/Downloads/HelloWorld/build/Debug-iphonesimulator/HelloWorld.app
CpResource build/Debug-iphonesimulator/HelloWorld.app/PakistanFlag.png PakistanFlag.png
cd /Users/kevin/Downloads/HelloWorld
setenv PATH “/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks /Users/kevin/Downloads/HelloWorld/PakistanFlag.png /Users/kevin/Downloads/HelloWorld/build/Debug-iphonesimulator/HelloWorld.app
Touch /Users/kevin/Downloads/HelloWorld/build/Debug-iphonesimulator/HelloWorld.app
cd /Users/kevin/Downloads/HelloWorld
setenv PATH “/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
/usr/bin/touch -c /Users/kevin/Downloads/HelloWorld/build/Debug-iphonesimulator/HelloWorld.app
======================
I can press “build” over and over again, and the output goes back and forth between the two outputs I listed above. One with the copying of the resources and one without.
As a result, if I switch build targets, I am getting an incorrect Default.png every other time I run.
Any idea what’s going wrong?
Hi Adeeb,
I there a way to do conditional inclusion of frameworks too? Something like MessageUI.framework inclusion for 3.0 and not for 2.2.1? Maybe I’m missing out something very basic in the settings?
Thanks
Hi Adeem,
Thanks for your post. I have used this way and it work fine.
However, today I build project again and the XCode show 1 error:
“Run script runTimeScript.sh Permission denied”
I don’t know how to fix it. Please help.
Thanks in advance.
I love what you guys are up to at http://adeem.me/blog/2009/05/03/tutorial-part-2-same-xcode-project-create-multiple-products-for-iphone-using-script/. This type of clever work and exposure! I wish I could do the same. Keep up the very good works guys I’ve included you guys to my blogroll.
Nice post.
Thanks Adeem,
Great tutorial! The supplied demo worked great on Xcode 4 but when I it on a new project I get.
Shell script invocation error
/Users/…../myApp.build/Script-6568843B13FEA39D009E8DD8.sh: line 2: ./runtimeScript: No such file or directory
It doesn’t even appear to run my runtimeScript.h file as I removed any of the cp statements just so I know it wasn’t to do with the images being in the wrong folders etc. I followed the instructions exactly and am experienced with Xcode 4.
Anyone have any ideas?
bazmcbrien@yahoo.com