Is it possible to add a folder to an Xcode project as a group with Applescript, recursively adding everything below it as if it were dragged to the Groups & Files list?
I don't do exactly that, but I do a very similar thing. I run the following shell command as a post-build command: (I've broken it into several lines so it's easier to read)
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp
-exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks
$FOLDER $APP_FOLDER
This command copies $FOLDER
to your app, and $APP_FOLDER
is the location of the (built) .app
folder, not the Xcode project. For example, my command expands out to
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp
-exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks
/Users/beder/src/myproj/data
/Users/beder/src/myproj/build-iphone/Debug-iphonesimulator/Myproj.app
(My build system uses CMake, which is why the .app
folder is in a bit of an unconventional location.)
The net result is that the data folder is copied to the .app
folder (as you would expect - ../Myproj.app/data/
). This bypasses copying it to Xcode, but I've found that I have no need for the folder to appear in Xcode. After each build, it copies the folder, so I can use the files in it as if I had dragged the folder to Xcode.
Obviously this isn't applescript, but you can execute a shell command in applescript by
do shell script "whatever"
I needed all files in subdirectories, apart from lproj directories, to be flat in the .app bundle. The assets were in this structure:
${assetsDir}/${targetCode}/
Icon.png
en.lproj
ja.lproj
...
*.lproj
resources{$targetCode/
Target.plist
audio/Audio.plist
*.mp3
I added a Run Script build phase prior to "Copy Bundle Resources" with something similar to following:
COPY_COMMAND="$DEVELOPER_LIBRARY_DIR/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp"
copyPNGCommand="$PLATFORM_DEVELOPER_LIBRARY_DIR/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/copypng"
lprojDirectories=$( find ${assetsDirectory}/${targetCode} -type d -name *lproj )
for lprojDirectory in $lprojDirectories; do
"$COPY_COMMAND" -exclude .DS_Store -exclude .svn -resolve-src-symlinks "$lprojDirectory" "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
done
MP3s=$( find ${assetsDirectory}/${targetCode}/resources${targetCode} -type f -name *.mp3 )
for MP3 in $MP3s; do
filename=$( basename "$PNG" )
"$COPY_COMMAND" -resolve-src-symlinks "$MP3" "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
done
PNGs=$( find ${assetsDirectory}/${targetCode}/resources${targetCode} -type f -name *.png )
for PNG in $PNGs; do
if [ -x "$copyPNGCommand" ]; then
filename=$( basename "$PNG" )
"$copyPNGCommand" -compress "" "$PNG" "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/$filename"
else
"$COPY_COMMAND" -resolve-src-symlinks "$PNG" "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
fi
done
Plists=$( find ${assetsDirectory}/${targetCode}/resources${targetCode} -type f -name '*.plist' )
for Plist in $Plists; do
"$XCODE_APP_SUPPORT_DIR/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist" --convert binary1 "$Plist" --outdir "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
done
Note: copypng only works when building for the device, hence the test