Skip to content

Commit 08f87e1

Browse files
author
Chris Wilson
committed
adds a sample script for opening latest simulator core data files.
1 parent 388326b commit 08f87e1

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

tools/bin/createCoreDataProject.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
##################
3+
# Creates a project for the most recent simulator instance.
4+
#
5+
# Usage:
6+
# createCoreDataProject.sh [MODEL_NAME] [PERSISTENT_STORE] [PROJECT_FILE_NAME]
7+
#
8+
# MODEL_NAME - The file name of the applications model file. (NSManagedObjectModel)
9+
#
10+
# PERSISTENT_STORE - This is the name of persistent store. (NSPersistentStoreCoordinator)
11+
#
12+
# PROJECT_FILE_NAME - The name that the project file will be staved to.
13+
#
14+
##################
15+
16+
if [ "$#" -ne 3 ]; then
17+
echo "Illegal number of parameters"
18+
echo "-------------------"
19+
echo "Usage:"
20+
echo ""
21+
echo "createCoreDataProject.sh [MODEL_NAME] [PERSISTENT_STORE] [PROJECT_FILE_NAME]"
22+
echo ""
23+
echo "MODEL_NAME - The file name of the applications model file. (NSManagedObjectModel)"
24+
echo ""
25+
echo "PERSISTENT_STORE - This is the name of persistent store. (NSPersistentStoreCoordinator)"
26+
echo ""
27+
echo "PROJECT_FILE_NAME - The name that the project file will be staved to."
28+
echo "-------------------"
29+
exit -1
30+
fi
31+
32+
33+
BIN_DIR=`dirname "$0"`
34+
SIM_DIR=~/Library/Developer/CoreSimulator/Devices
35+
DEST_DIR=/tmp
36+
37+
PROJECT_NAME=$3
38+
MODEL_NAME=$1
39+
DATA_NAME=$2
40+
41+
# get last modified simulator folder (should be active/last running simulator)
42+
LAST_MODIFIED=`ls -t $SIM_DIR | head -1`
43+
44+
CONTAINER_DIR=$SIM_DIR/$LAST_MODIFIED/data/Containers
45+
cd $CONTAINER_DIR
46+
47+
# find model
48+
MODEL_PATH=`find . -name $MODEL_NAME`
49+
50+
# find data file
51+
DATA_PATH=`find . -name $DATA_NAME`
52+
53+
# create project file
54+
rm $DEST_DIR/$PROJECT_NAME
55+
/usr/libexec/PlistBuddy -c "Add :modelFilePath string \"file://$CONTAINER_DIR/$MODEL_PATH\"" $DEST_DIR/$PROJECT_NAME
56+
/usr/libexec/PlistBuddy -c "Add :storeFilePath string \"file://$CONTAINER_DIR/$DATA_PATH\"" $DEST_DIR/$PROJECT_NAME
57+
/usr/libexec/PlistBuddy -c "Add :storeFormat integer 1" $DEST_DIR/$PROJECT_NAME
58+
/usr/libexec/PlistBuddy -c "Add :v integer 1" $DEST_DIR/$PROJECT_NAME
59+
60+
echo "project created: $DEST_DIR/$PROJECT_NAME"
61+
62+
open $DEST_DIR/$PROJECT_NAME
63+
# read -p "open project? (y/n) " yn
64+
# case $yn in
65+
# [Yy]* ) open $DEST_DIR/$PROJECT_NAME; break;;
66+
# * ) exit ;;
67+
# esac

0 commit comments

Comments
 (0)