views:

1141

answers:

3

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  A: 

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.

weichsel
Ah, cool. I had not found that setting. Of course, when you create a new project, the default template files you get will always have the globally-defined value, but it looks like changing this setting will apply correctly to new files added to the project going forward. I guess that's about as good as I'm going to get -- thanks!
bmoeskau
+1  A: 

@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.

bmoeskau