Skip to content

Instantly share code, notes, and snippets.

@alobaili
Last active March 28, 2020 16:42
Show Gist options
  • Save alobaili/aaa94bc2a67694c519b0bab93d41b57f to your computer and use it in GitHub Desktop.
Save alobaili/aaa94bc2a67694c519b0bab93d41b57f to your computer and use it in GitHub Desktop.
Open a terminal window at Xcode project directory

You can make Xcode automatically open a terminal at the current directory using a shortcut you specify. Here are the steps:

  1. create an empty shell scrip file with the name open_terminal.sh and paste the following content in it:
#!/bin/bash

# I mainly use this as a behavior in Xcode to open
# Terminal at the project's working directory.

open -a Terminal "`pwd`"

# Optional script to make the opened window fullscreen.
# you can delete it if you don't want fullscreen.
# make sure to read step 2 bellow to make it work.
osascript <<EOD
    tell application "System Events" to tell process "Terminal"
        delay 0.75
        set value of attribute "AXFullScreen" of window 1 to true
    end tell
EOD
  1. Optional step: If you want to run the optional script and allow terminal to open in fullscreen, give Xcode access to accessibility features from System Preferences > Security & Privacy > Privacy > Accessibility > + > locate and select Xcode.

  2. From Xcode: Go to Preferences > Behaviors and click the + icon to create a custom behavior.

  3. give it a name, for example: "Open Terminal"

  4. Optionally give the behavior a shortcut.

Screen Shot 2020-03-24 at 21 48 06

  1. Check the Run box and click "Choose Script..." in the dropdown menu.

  2. locate the shell script file you created and select it.

  3. If the shell script file can't be selected, open a terminal in the directory where the file is located and run the following command:

chmod +x open_terminal.sh

then try to select the file again.

  1. You can now trigger the behavior by using your shortcut or from the menubar under Xcode > Behaviors.

That's it! you now have an Xcode behavior to make your life easy :)

p.s. If the fullscreen script doesn't work try modifying the delay from 0.75 to a longer interval to give time for the terminal window to launch before attempting to make it fullscreen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment