如何从终端运行 xcode?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19639914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:59:28  来源:igfitidea点击:

How to run xcode from terminal?

xcodemacos

提问by feelfree

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

我的问题很简单:假设有一个 xcode 项目 a.xcodeproj,我可以使用以下命令打开它:xcode a.xcodeproj

If I try this, I receive the following error message:

如果我尝试此操作,则会收到以下错误消息:

-bash: xcode: command not found

回答by SheetJS

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

Xcode 应该是 .xcodeproj 文件的默认应用程序,所以这应该可以工作:

$ open a.xcodeproj

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

如果这会打开一个不同的应用程序,您可以强制它使用 xcode:

$ open -a Xcode a.xcodeproj

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

如果你想让命令xcode工作,你可以给它别名:

$ alias xcode="open -a Xcode"

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

然后你可以xcode a.xcodeproj(并将其添加到~/.bash_profile

回答by Gobe

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:

您也可以简单地xed .在项目的根目录中运行,显然它会尝试以分层方式加载项目,即第一个存在的项目:

  1. the folder, if it's a Package (Xcode 11+)
  2. xcworkspace
  3. xcodeproj
  4. playground
  1. 文件夹,如果它是一个包(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.

这意味着您无需验证自己现有的文件结构即可选择最好的文件结构来打开。

回答by Eugene

Following command should do it:

以下命令应该这样做:

open a.xcodeproj

回答by danielbeard

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

不记得我在哪里遇到过这个脚本,但我使用这个 ruby​​ 脚本在工作目录中查找 a*.xcodeproj*.xcworkspace文件并打开该文件(没有 Xcode 打开任何以前的项目)

#!/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

回答by arango_86

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

以防万一,如果您想从工作区打开 Xcode 项目,请使用以下命令行。

user$ open -a xcode ProjectName.xcworkspace/

回答by Dheeraj Gupta

open terminal, then go to the path where Xcode is installed. Then, go to its "Contents/MacOS". And when you reach this folder, then type - sudo ./Xcode

打开终端,然后转到安装Xcode的路径。然后,转到其“内容/MacOS”。当你到达这个文件夹时,然后输入 - sudo ./Xcode

Or else follow the following code: (you can use "sudo" if the user has privilege issue)

或者按照以下代码:(如果用户有权限问题,您可以使用“sudo”)

cd /  
cd Applications
cd Xcode.app
cd Contents/MacOS
sudo ./Xcode

回答by Nik

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

我只是输入open *xcw*. 此命令在当前目录中查找工作区,然后使用 Xcode 打开。