Define __MyCompanyName__ in Xcode per project?

Viewed 20335

I've seen how to define the __MyCompanyName__ macro value that displays in all header comments in XCode by defining it globally via a terminal command:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My Company";}'

However, I do work under multiple company names and would like an easy way to switch this depending on what project I'm working on. I realize that I can just write a simple shell script to do this, but then I still have to remember to run it every time I open a project. Am I missing an easy way to define this per project statically somewhere? (This seems like a silly hoop to have to jump through... Apple, hello?)

7 Answers

Since Xcode 3.2 (IIRC) this is a per-project setting.
Just "Get Info" on your project in Xcode. It's right there on the "General" tab.

Update The above answer is for Xcode 3.2. See Sri Sankaran's & aeldron's answers below for Xcode 4.

Update Also appropriate for Xcode 4 is the first part of trtwn's answer below. in other words, setting the "company" in the address book is one way to solve the problem in case the company will always be the same for all New files created in Xcode on a particular mac.

@weichsel's answer is accepted as it solves this for most normal people ;), but I switch this setting often enough that getting the template-generated files with the statically-defined company name is still a bit of an annoyance each time I start a new project. Having to do the "Get Info then type the name" dance also takes up too much time if you do it often enough. Here's my ultimate solution:

  • Create a folder like "Set Company" with my shell scripts in it for each company I use
  • Each script contains a version of this terminal command specific to each company:

    defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My Company";}'

  • I make each script executable so that I can simply double-click in Finder to set my current company. This page helped me set this up. Basically, you just

    • Rename each .sh script file to .command
    • Set the permissions of each script to be executable. I couldn't figure out how to do this in Finder, but in terminal it's simply chmod +x mycompany.command

Easy as that. Now to start a new project I simply double-click whichever company I plan to use then I'm off to coding. Hope this helps someone else.

Related