How to run xcode from terminal?

后端 未结 7 2372
挽巷
挽巷 2020-12-23 11:37

My question is very simple: suppose there is an xcode project a.xcodeproj, could I open it with the command: xcode a.xcodeproj?

If I try this, I receiv

相关标签:
7条回答
  • 2020-12-23 11:38

    incase, if you want to open a Xcode project from a workspace use the following command line.

    user$ open -a xcode ProjectName.xcworkspace/
    
    0 讨论(0)
  • 2020-12-23 11:38

    I just type open *xcw*. This command looks up a workspace in the current directory and then opens is with Xcode.

    0 讨论(0)
  • 2020-12-23 11:46

    Following command should do it:

    open a.xcodeproj
    
    0 讨论(0)
  • 2020-12-23 11:50

    Can't remember where I came across this script, but I use this ruby script for finding either a *.xcodeproj or *.xcworkspace file in the working directory and opening that file (without Xcode opening any previous projects)

    #!/usr/bin/env ruby
    
    # Open xcode without any previous projects being opened as well.
    # We first look for a workspace, then a project in the current directory, opening the first that is found.
    
    f = []
    f.concat Dir["*.xcworkspace"]
    f.concat Dir["*.xcodeproj"]
    
    if f.length > 0
      puts "opening #{f.first}"
      `open -a /Applications/Xcode.app #{f.first} --args -ApplePersistenceIgnoreState YES`
      exit 0
    end
    
    puts "No Xcode projects found"
    exit 1
    
    0 讨论(0)
  • 2020-12-23 11:58

    You could also simply run xed . in the project's root directory, apparently it will try to load a project in a hierarchical manner, i.e. the first that exists:

    1. the folder, if it's a Package (Xcode 11+)
    2. xcworkspace
    3. xcodeproj
    4. playground

    which means you don't need to verify yourself the existing file structure in order to choose the best one to open.

    0 讨论(0)
  • 2020-12-23 12:00

    Xcode should be the default application for .xcodeproj files, so this should work:

    $ open a.xcodeproj
    

    If that opens a different application, you can force it to use xcode:

    $ open -a Xcode a.xcodeproj
    

    If you want the command xcode to work, you can just alias it:

    $ alias xcode="open -a Xcode"
    

    then you can just xcode a.xcodeproj (and add this to ~/.bash_profile)

    0 讨论(0)
提交回复
热议问题