xcode 在Xcode中调试时自动打开终端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2553623/
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-14 19:14:56  来源:igfitidea点击:

Automatically open terminal when debugging in Xcode?

xcodemacosautomationterminal

提问by drewh

When debugging an executable in Xcode, I very often have to open up a terminal window, navigate to the executable's working directory and do some work there. Is there any way to have Xcode automatically open a terminal window at this location each time I debug my program?

在 Xcode 中调试可执行文件时,我经常需要打开一个终端窗口,导航到可执行文件的工作目录并在那里做一些工作。有什么办法可以让 Xcode 每次调试我的程序时在这个位置自动打开一个终端窗口?

采纳答案by WrightsCS

In Xcode, go to your Target, then right-click and choose:

在 Xcode 中,转到您的Target,然后右键单击并选择:

Add -> New Build Phase -> New Run Script Build Phase

Add -> New Build Phase -> New Run Script Build Phase

enter image description here

在此处输入图片说明

then add the following:

然后添加以下内容:

open /Applications/Utilities/Terminal.app

enter image description here

在此处输入图片说明

Now, every time you Build your app, Xcode will run this build script and launch Terminal. Note that you need to point to the correct location of the terminal application. Best way to do this is find the Terminal.app and drag and drop it onto the above screen after you type "open".

现在,每次构建应用程序时,Xcode 都会运行此构建脚本并启动终端。请注意,您需要指向终端应用程序的正确位置。最好的方法是找到 Terminal.app,然后在输入“open”后将其拖放到上面的屏幕上。

Once you have Terminal open, you will need to make an AppleScript to send the commands to Terminal to open the specific directory. Use the 'osascript' command to send an AppleEvent to Terminal.

打开终端后,您将需要制作 AppleScript 以将命令发送到终端以打开特定目录。使用“osascript”命令将 AppleEvent 发送到终端。

回答by Phil

For anyone who's still looking,

对于仍在寻找的任何人,

It's really easy.. say you want to click run and have the app run in the Terminal. Here's what you do:

这真的很容易.. 假设您想单击运行并在终端中运行应用程序。这是你要做的:

Go to Build Phases -> Editor -> Add Build Phase -> Add Run Script Build Phase -> Click the down arrow on Run Script -> Add the following:

转到 Build Phases -> Editor -> Add Build Phase -> Add Run Script Build Phase -> 单击 Run Script 上的向下箭头 -> 添加以下内容:

open /Applications/Utilities/Terminal.app /Users/yourusername/restofpath

打开 /Applications/Utilities/Terminal.app /Users/yourusername/restofpath

Notes: Spaces use '\ ' if needed. Include your app name in the path. Don't use quotes.

注意:如果需要,空格使用“\”。在路径中包含您的应用程序名称。不要使用引号。

Click Run, and there you go!

单击运行,然后就可以了!

If you want the Terminal to clear, in your source code type 'system("clear")' near main(). It's the only solution I have while debugging. Works great.

如果您希望终端清除,请在您的源代码中在 main() 附近键入“system("clear")”。这是我在调试时唯一的解决方案。效果很好。

回答by C0DEF52

Check my answer hereto see how to setup Xcode scheme to fully automate debugging with using Terminal. I described it for ncurses that requires real Terminal to work.

在此处查看我的答案以了解如何设置 Xcode 方案以使用终端完全自动化调试。我为需要真正终端才能工作的 ncurses 描述了它。