Skip to content

Instantly share code, notes, and snippets.

@odemolliens
Forked from shazron/sim-run.sh
Created December 23, 2016 08:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save odemolliens/c77645c5e42e5de3233d8b1948f9a3a4 to your computer and use it in GitHub Desktop.
Save odemolliens/c77645c5e42e5de3233d8b1948f9a3a4 to your computer and use it in GitHub Desktop.
Run Xcode Simulator project from the command line XCode 8
#!/bin/bash
#
# Build and iPhone Simulator Helper Script
# Shazron Abdullah 2011
#
# WARN: - if your .xcodeproj name is not the same as your .app name,
# this won't work without modifications
# - you must run this script in where your .xcodeproj file is
PROJECTNAME=$1
CONFIGURATION=$2
LOGFILE=$3
function help
{
echo "Usage: $0 <projectname> [configuration] [logname]"
echo "<projectname> name of your .xcodeproj file (and your .app as well)"
echo "[configuration] (optional) Debug or Release, defaults to Debug"
echo "[logname] (optional) the log file to write to. defaults to stderror.log"
}
# check first argument
if [ -z "$PROJECTNAME" ] ; then
help
exit 1
fi
# check second argument, default to "Debug"
if [ -z "$CONFIGURATION" ] ; then
CONFIGURATION=Debug
fi
# check third argument, default to "stderror.log"
if [ -z "$LOGFILE" ] ; then
LOGFILE=stderr.log
fi
# backup existing logfile (start fresh each time)
if [ -f $LOGFILE ]; then
mv $LOGFILE $LOGFILE.bak
fi
touch -cm www
xcodebuild -configuration $CONFIGURATION -sdk iphonesimulator -project $PROJECTNAME.xcodeproj
ios-sim launch build/$CONFIGURATION-iphonesimulator/$PROJECTNAME.app --stderr $LOGFILE --exit
osascript -e "tell application \"Simulator\" to activate"
tail -f $LOGFILE
@AlexNsbmr
Copy link

Hi, thank you for your useful script. Would it be possible to update your code and add support for .workspace based projects ?

@asadali737
Copy link

Hi, thank you for your useful script. Would it be possible to update your code and add support for .workspace based projects ?

Just replace -project $PROJECTNAME.xcodeproj with -workspace $PROJECTNAME.xcworkspace
Also you need to specify the -scheme <your_scheme_name> as a new argument.

Your complete command would be like
xcodebuild -configuration $CONFIGURATION -sdk iphonesimulator -workspace $PROJECTNAME.xcworkspace -scheme <your_scheme_name>

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