4

是否可以使用 Applescript 将文件夹作为一个组添加到 Xcode 项目中,递归地添加它下面的所有内容,就好像它被拖到 Groups & Files 列表中一样?

4

2 回答 2

2

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

于 2009-10-23T01:33:36.930 回答
2

我不完全那样做,但我做了一个非常相似的事情。我将以下 shell 命令作为构建后命令运行:(我已将其分成几行,以便于阅读)

/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp
   -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks
   $FOLDER $APP_FOLDER

此命令复制$FOLDER到您的应用程序,并且$APP_FOLDER是(构建).app文件夹的位置,而不是Xcode 项目。例如,我的命令扩展到

/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

(我的构建系统使用 CMake,这就是为什么该.app文件夹位于一个非常规位置的原因。)

最终结果是将数据文件夹复制到该.app文件夹​​中(如您所料 - ../Myproj.app/data/)。这绕过了将其复制到 Xcode,但我发现我不需要该文件夹出现在 Xcode 中。每次构建后,它都会复制文件夹,因此我可以使用其中的文件,就好像我已将文件夹拖到 Xcode 中一样。

显然这不是applescript,但你可以在applescript中执行一个shell命令

do shell script "whatever"
于 2009-10-21T03:21:29.077 回答