63

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?)

2
  • 5
    Note that you can set the global default by specifying your company name in Address Book. No need for defaults write .... Jan 5, 2010 at 19:52
  • Yeah, I saw that somewhere. Still doesn't really address my issue though ;) Jan 5, 2010 at 20:47

7 Answers 7

122

Screenshot of Xcode 4.1.

@neoneye See screenshot of how it's done with Xcode 4.1 (OS X Lion -- if that matters).

2
  • 5
    +1 Ahem, this is the real answer for xcode 4+ .. thanks for the hand holding graphic!!!
    – Rob
    Aug 24, 2011 at 15:15
  • Thank you! I couldn't find this anywhere else.
    – DOOManiac
    Feb 18, 2012 at 3:18
51

You can set the value in the project's info settings. In Xcode 4:

  1. select the blue project icon
  2. open the Utilities Pane if it's closed (Option+Command+1)
  3. Type in the Organization field in the Project Document section.

Voila!

enter image description here

2
  • 2
    anyway to set it before you create the template project, so you don't have to go search and replace the occurences created by template before you can change the organization?
    – marchinram
    Jun 30, 2011 at 6:52
  • I cannot find any Organization field in the settings. Can you post a screenshot?
    – neoneye
    Jul 19, 2011 at 14:52
20

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.

2
  • 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! Jan 5, 2010 at 20:56
  • 1
    Reference aeldron's response for the XCode 4 solution
    – BBonifield
    Oct 21, 2011 at 19:30
17

As for Xcode 4, the Release Notes state

The ORGANIZATIONNAME substitution value in templates is now replaced with the Company Name from the current user’s Address Book card if present, rather than _MyCompanyName_. If the PBXCustomTemplateMacroDefinitions user default has already been set, it will be honored.

Yet, the latter was not the case for me.

0
7

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

1
2

Best fix for My Company. in XCode 4:

Open your Address Book card and give yourself a company name. You should do this from System Preferences to make sure you are changing the correct User.

On you Mac –> Select System Preferences –> Select Users and Groups –> Click once on Your User ID –> Click on Address Book Card ‘Open’ button. This is the contact associated with your User account. Add a company name here (just under your name). Close XCode if it’s open. Open Xcode and give it a try. Good luck.

1

Try this:

  1. Open Contacts
  2. Make sure you are on the contact list
  3. Make sure your contact card is assigned to "My Card" if not select it from "Make this My Card" from Card menu. enter image description here

  4. Make sure that your company is set on your card.

  5. Your card should look like this: (on your picture is should say "me") enter image description here

Next time you create a new project or create a new file your company name will be as it is defined in your contact card.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.