Define __MyCompanyName__ in Xcode per project?
XcodeXcode Problem Overview
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?)
Xcode Solutions
Solution 1 - Xcode
Screenshot of Xcode 4.1.
Solution 2 - Xcode
You can set the value in the project's info settings. In Xcode 4:
- select the blue project icon
- open the Utilities Pane if it's closed (Option+Command+1)
- Type in the Organization field in the Project Document section.
Voila!
Solution 3 - Xcode
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.
Solution 4 - Xcode
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.
Solution 5 - Xcode
@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.
Solution 6 - Xcode
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.
Solution 7 - Xcode
Try this:
-
Open Contacts
-
Make sure you are on the contact list
-
Make sure your contact card is assigned to "My Card" if not select it from "Make this My Card" from Card menu.
-
Make sure that your company is set on your card.
-
Your card should look like this: (on your picture is should say "me")
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.