Duc Ninja

Open Terminal from Xcode


You are using third-party tools like CocoaPods, Cathage, SPM or just having some useful script files for your project. It’s fine!

But you often found yourself in need of opening a Terminal window at the project location. It hard to tell that feeling. 🤔 Don’t worry, here is what you need to do:

1. Create a sh file

Create a new text file with your favourite text editor and put this inside:

#! /bin/bash
open -a Terminal "$SRCROOT"



if [ -n "$XcodeProjectPath" ]; then	
  open -a Terminal "$XcodeProjectPath"/..
  open -a Terminal "$XcodeWorkspacePath"/..

It opens either .xcodeproj or .xcworkspace.

If you prefer iTerm, just change the Terminal keyword to iTerm in this script. I’m using iTerm too, so I created a bash file like this:

Create script file

2. Store the file

Save it with a .sh extension in some permanent location where your wife or your girlfriend wouldn’t see it everyday so it annoys them, and they won’t delete it by mistake.

3. Grant execute permission

Navigate to the location of the script file you just created using Terminal and change its permissions using:

  chmod +x <fileName>

where fileName should be replaced with the name of the .sh file you just created.

4. Add a custom behavior

In Xcode, go to Preferences -> Behaviors and click the plus sign in the bottom to add a new behavior and name it something like “Open Terminal”

Tick only the last checkbox, where it says “Run”, and select the location of your .sh file.

5. Assign a key

Click the little ⌘ symbol to the right of your behavior name and select a new keyboard shortcut for your behavior. I recommend: ctrl+command+t.

That’s it, you’re done! 🎉 🎉 🎉

You can get my sh file here: xcode-terminal.sh