Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open the first Xcode workspace or project found
xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`
if [ `echo -n $xcode_proj | wc -m` == 0 ]
then
echo "No xcworkspace/xcodeproj file found in the current directory."
exit 1
fi
echo "Found $xcode_proj"
open $xcode_proj
@mmorey
Copy link

mmorey commented Apr 21, 2013

If an xcode project name has spaces in it this fails for me. I had to replace

open $xcode_proj

With

open "$xcode_proj"

I am using it as a function inside my .bash_profile

xc(){
    xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`

    if [ `echo -n $xcode_proj | wc -m` == 0 ]
    then
        echo "No xcworkspace/xcodeproj file found in the current directory."
    else
        echo "Found $xcode_proj"
        open "$xcode_proj"
    fi
}   

@blakejakopovic
Copy link

blakejakopovic commented Jul 17, 2013

If your using Zsh, try the following

function xc {
    xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`

    if [[ `echo -n $xcode_proj | wc -m` == 0 ]]
    then
        echo "No xcworkspace/xcodeproj file found in the current directory."
    else
        echo "Found $xcode_proj"
        open "$xcode_proj"
    fi
}

@Tagalong
Copy link

Tagalong commented Mar 26, 2014

I get the project open but then I get an error in the open project

myProject.xcodeproject could not be opened

What's going on?

@Somebaby
Copy link

Somebaby commented Sep 13, 2018

only excute xc :
Found TestProj.xcodeproj. Opening with /Library/Developer/CommandLineTools
The application /Library/Developer/CommandLineTools cannot be opened because its executable is missing.
Please Help me!

I Have installed Xcode command line Tool.

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