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

Undo's user avatar

Undo

25.7k38 gold badges114 silver badges132 bronze badges

asked Jan 5, 2010 at 18:03

Brian Moeskau's user avatar

2

122

Screenshot of Xcode 4.1.

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

answered Aug 20, 2011 at 3:37

Sri Sankaran's user avatar

1 Comment

+1 Ahem, this is the real answer for xcode 4+ .. thanks for the hand holding graphic!!!

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

answered Mar 16, 2011 at 12:05

aeldron's user avatar

aeldron

1,5751 gold badge13 silver badges16 bronze badges

2 Comments

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?

I cannot find any Organization field in the settings. Can you post a screenshot?

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.

john.k.doe's user avatar

john.k.doe

7,5533 gold badges39 silver badges64 bronze badges

answered Jan 5, 2010 at 19:19

Thomas Zoechling's user avatar

2 Comments

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!

Reference aeldron's response for the XCode 4 solution

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.

answered Nov 5, 2010 at 16:58

trautwein's user avatar

trautwein

4871 gold badge5 silver badges14 bronze badges

Comments

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.

answered Feb 9, 2010 at 17:34

Brian Moeskau's user avatar

1 Comment

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.

answered Aug 25, 2012 at 19:56

Best Answer Guy's user avatar

Comments

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.

answered May 27, 2013 at 3:20

Tibidabo's user avatar

Tibidabo

21.5k5 gold badges93 silver badges88 bronze badges

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.