Tuesday, January 27, 2009

Renaming an XCode Project from Command Line

UPDATE: As of Xcode 3.2 you can rename projects from the Projects->Rename dropdown.

Earlier I had posted how to manually rename an XCode project. I have now written a BASH shell script to handle everything automatically. You can find it here.

23 comments:

Troy McD said...

Thank you, thank you, THANK YOU!

Frank said...

Worked for me too. Thank you!

Mobile Developer said...

Hey Man,

You are amazing. You saved my whole day. I was trying to rename one very very big project.

Thank you very much..

// Ganesh Pisal

Girish said...

Cheers dude! That worked like a charm. Thanks very much! :)

Sebastian said...

I tried it, but it only works if the projectnames contain spaces. Mine did not, so there I propose a little patch.

Replace the sed for eliminating the spaces with the following code:

OLDNAMEU=${OLDNAME}
NEWNAMEU=${NEWNAME}

# create name with underscores
echo "${OLDNAME}" | grep " " > /dev/null
if [ $? -eq 0 ]; then
OLDNAMEU = `echo "${OLDNAME}" | sed -e "s/ /_/g"`
fi

echo "${NEWNAME}" | grep " " > /dev/null
if [ $? -eq 0 ]; then
NEWNAMEU = `echo "${NEWNAME}" | sed -e "s/ /_/g"`
fi

It is then doing some duplicate sedding, and grepping and finding, but that did not matter for me.

Great work and many thanks

Sebastian

mohrt said...

@Sebastian I rename XCode projects without spaces all the time. I'm not sure why you needed to adjust something to make it work.

L said...

It works perfectly, and is a great help. Very many thanks.

Ingo Schruf said...

This sounds amazing. I have to rename my project as I used a name containing spaces which Apple doesn't really seem to like...

How do I use your tool if my filename contains spaces?

Cause looking at your example:

renameXcodeProject.sh MyStuff MyNewStuff

a space in the first part could cause problems?

Thanks a lot!
ingo.

mohrt said...

If your project has spaces, use quotes around the names.

./renameXcodeProject "old name" "new name"

tehZoe said...

Everything worked fine except that one of my two xib files won't load in Interface Builder.

Building target “PQR” of project “PQR” with configuration “Release” — (1 error)
cd /Users/tehZoe/Desktop/PQR
setenv PATH "/Developer3.1.3Beta5/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer3.1.3Beta5/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer3.1.3Beta5/usr/bin/ibtool --errors --warnings --notices --output-format human-readable-text --compile /Users/holbrook/Desktop/PQR/build/Release-iphonesimulator/PQR.app/PQRView.nib /Users/tehZoe/Desktop/PQR/PQRView.xib
/* com.apple.ibtool.errors */
Internal Error:
Description: The document "PQRView.xib" could not be opened. An instance of IBUIPQRView could not be decoded.
Recovery Suggestion: Ensure all plug-ins used to create this document have been loaded.
Build failed (1 error)

mohrt said...

@tehZoe did you delete the build directory?

Mikey Cee said...

This is outstanding work! Worked perfectly, thanks.

Matt said...

This is awesome. Thanks a lot for doing this!

Kuki said...

Too good !! Worked very well !! Thanks a ton for writing it :) !!

wolfscliff said...

renameXcodeProject.sh is a lifesaver, thank you !

Unknown said...

Huge thanks!!!!! You just saved me a HUGE amount of hassle.

Dr Bourbon said...

thanks!!

Matthew said...

Thanks mate, amazing!

Unknown said...

work like a charm!

Unknown said...

Hey,

completely noob question, but where do i even start with using this file?! no idea what 'Copy (this) file "renameXcodeProject.sh" to your file system, and invoke:' even means !

thanks

mohrt said...

You do this through the terminal application of OSX. You need to know a little bit about the unix command line.

Future Primitive said...

Thank you!

Just what I was looking for.

Arius said...

WOW!!! that is supercool, worked like charm!
I usually don't get this excited... anyway big ups!