6

Xcode 4 is still my main IDE for iOS development. To try the upcoming iOS 7 I installed Xcode 5 Developer Preview and now all the files that were used to open in Xcode 4 now open in Xcode 5.

How can I revert Xcode 4 to be default editor again without uninstalling Xcode 5?

svlasov
  • 9,923
  • 2
  • 38
  • 39

2 Answers2

4

After reading about LaunchServices in OS X I have finally found the solution, thanks for the hint @peter-m.

To modify files association for certain app one can use lsregister tool. So to re-register the app there is -f parameter, and to unregister -u. Everything can be in fact done with just one command:

$ lsregister -f /Applications/Xcode.app

Or if you want to unregister Xcode 5 and not touch manually set associations earlier:

$ lsregister -u /Applications/Xcode5-DP5.app

lsregister is located in /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/, so add it to your $PATH

Re-login to OS X for changes to apply.

svlasov
  • 9,923
  • 2
  • 38
  • 39
  • Nice! `.../lsregister -u /Applications/Xcode5-DP5.app` did the trick for me. The other proposed solution (file -> get info -> open with: xcode -> change all) did not work. – pix0r Sep 05 '13 at 22:16
2

Assuming you don't have any Xcode 5 projects yet, how about manually:

  1. Find an existing XCode 4 project (*.xcodeproj) with the Finder
  2. Do a Get Info of the file
  3. Change Open with: to your desired version of Xcode
  4. Click on Change All
  5. Repeat for all types of files that you want to open with XCode 4

Or if you want to try something more automatic take a look at: programmatically-script-atically-changing-the-default-open-with-setting

Based on the comment below, the problem seems to be with command line builds picking the wrong version of Xcode. In that case I suggest looking at: xcode-build-and-archive-from-command-line, especially the Reid's comment to his own answer which says:

Works fine in Xcode 4.4, and I'm sure it was fine in 4.3 as well. Make sure you have selected the correct Xcode release by using:

xcode-select <path to Xcode.app>

So perhaps the correct solution is based around understanding:

xcode-select -- Manages the path to the Xcode folder for Xcode BSD tools.

Community
  • 1
  • 1
Peter M
  • 7,309
  • 3
  • 50
  • 91
  • There are way too many file types besides *.xcodeproj. I was hoping to find a solution that does the job for all Xcode files at once. – svlasov Aug 13 '13 at 12:26
  • @svlasov Once you get past the project files, .h and .m files what else is really needed for manually opening a file? Are you implying that OSX is using `Open with` information when XCode is implicitly opening files buried deep down in a project? I would have assumed that once the correct version of XCode is running that it would be explicitly opening files and not replying on `open with` – Peter M Aug 13 '13 at 12:39
  • Browsing files withing Xcode project indeed has nothing to do with `Open with` association. I have problem with 3rd party libraries that use command line for building and don't have .xcodeproj files per se. – svlasov Aug 13 '13 at 13:09
  • @svlasov That seems to be a different problem to the question you asked. It sounds like a more correct question is `How do I change the command line build automation of third party (source code) libraries to use a specific version of XCode` – Peter M Aug 13 '13 at 13:22
  • The problem is not with building but opening/editing the files. – svlasov Aug 13 '13 at 13:27
  • @svlasov OK .. now I am confused. Can you explicitly list out what you want to do with these files that don't have an XCode project but are being built with Xcode? – Peter M Aug 13 '13 at 13:30
  • I want to use Xcode 4 as file editor, so it would open for all the files as it used to open before installing Xcode 5. I'm playing right now with WebRTC on iOS. The latest revisions don't use .xcodeproj anymore and the project is build with ninja tool from .gyp files. Yet all the standard iOS source file types are there: .h, .m, .mm, .c, .cc, .plist, .xib, .xml and others. I posted the solution below. – svlasov Aug 13 '13 at 13:58