Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adds a sample script for opening latest simulator core data files.
  • Loading branch information
Chris Wilson committed Dec 2, 2014
1 parent 388326b commit 08f87e1
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tools/bin/createCoreDataProject.sh
@@ -0,0 +1,67 @@
#!/bin/bash
##################
# Creates a project for the most recent simulator instance.
#
# Usage:
# createCoreDataProject.sh [MODEL_NAME] [PERSISTENT_STORE] [PROJECT_FILE_NAME]
#
# MODEL_NAME - The file name of the applications model file. (NSManagedObjectModel)
#
# PERSISTENT_STORE - This is the name of persistent store. (NSPersistentStoreCoordinator)
#
# PROJECT_FILE_NAME - The name that the project file will be staved to.
#
##################

if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters"
echo "-------------------"
echo "Usage:"
echo ""
echo "createCoreDataProject.sh [MODEL_NAME] [PERSISTENT_STORE] [PROJECT_FILE_NAME]"
echo ""
echo "MODEL_NAME - The file name of the applications model file. (NSManagedObjectModel)"
echo ""
echo "PERSISTENT_STORE - This is the name of persistent store. (NSPersistentStoreCoordinator)"
echo ""
echo "PROJECT_FILE_NAME - The name that the project file will be staved to."
echo "-------------------"
exit -1
fi


BIN_DIR=`dirname "$0"`
SIM_DIR=~/Library/Developer/CoreSimulator/Devices
DEST_DIR=/tmp

PROJECT_NAME=$3
MODEL_NAME=$1
DATA_NAME=$2

# get last modified simulator folder (should be active/last running simulator)
LAST_MODIFIED=`ls -t $SIM_DIR | head -1`

CONTAINER_DIR=$SIM_DIR/$LAST_MODIFIED/data/Containers
cd $CONTAINER_DIR

# find model
MODEL_PATH=`find . -name $MODEL_NAME`

# find data file
DATA_PATH=`find . -name $DATA_NAME`

# create project file
rm $DEST_DIR/$PROJECT_NAME
/usr/libexec/PlistBuddy -c "Add :modelFilePath string \"file://$CONTAINER_DIR/$MODEL_PATH\"" $DEST_DIR/$PROJECT_NAME
/usr/libexec/PlistBuddy -c "Add :storeFilePath string \"file://$CONTAINER_DIR/$DATA_PATH\"" $DEST_DIR/$PROJECT_NAME
/usr/libexec/PlistBuddy -c "Add :storeFormat integer 1" $DEST_DIR/$PROJECT_NAME
/usr/libexec/PlistBuddy -c "Add :v integer 1" $DEST_DIR/$PROJECT_NAME

echo "project created: $DEST_DIR/$PROJECT_NAME"

open $DEST_DIR/$PROJECT_NAME
# read -p "open project? (y/n) " yn
# case $yn in
# [Yy]* ) open $DEST_DIR/$PROJECT_NAME; break;;
# * ) exit ;;
# esac

0 comments on commit 08f87e1

Please sign in to comment.