Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically open terminal when debugging in Xcode?

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?

like image 260
drewh Avatar asked Mar 31 '10 14:03

drewh


People also ask

How do I open the console in Xcode?

Go to Xcode → Preferences → Debugging → On Start → "Show Console". Save this answer.

Does Xcode have an integrated terminal?

Xcode is one of the few IDE's I know that does not have a "Open terminal" button. But you can leverage so called "Xcode Behaviors" to quickly launch your terminal. Xcode Behaviors allows you to execute shell scripts from Xcode with a keyboard shortcut.

How do I enable debug mode in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

Where is debug console in Xcode?

The default keyboard shortcut to show or hide the debug area is ⇧ ⌘ Y (shift-command-Y). Save this answer. Show activity on this post. You can click on small triangle at the bottom to see the console.


2 Answers

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:

open /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.

like image 107
Phil Avatar answered Oct 21 '22 03:10

Phil


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

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".

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.

like image 42
WrightsCS Avatar answered Oct 21 '22 03:10

WrightsCS