This is great, I get *much* further now. I'm basically using the logic you described below, but for each file, I need to parse off the directory and create a separate file copy for each unique directory (unfortunately, the headers have a directory structure!). The code goes through and first searches for an existing Copy Files for the directory, and if it doesn't find one, it'll create a new one. However, it looks like the 1st time it goes to add a file to a Copy Files that it created, I get the following:
add item 10 of every file reference of project "Test" to item 4 of every copy files phase of target id "902F729A05417B7700353415" of project "Test" "Xcode got an error: Target container does not support the add event."
It seems that if I'm adding to an aCopy that I created with:
set aCopy to make new copy files phase with properties {destination directory:wrapper, path:"Headers/" & aDir, run only when installing:false, comment:""}
Then the subsequent add works, however, if I get the aCopy instance by searching for it:
repeat with aCopy in every copy files phase of aTarget if ((destination directory of aCopy) is equal to wrapper) and ((path of aCopy) is equal to ("Headers/" & aDir)) then return aCopy
Then I don't seem to be able to add to it.
Thanks!!!
On Sep 22, 2005, at 11:14 PM, Rick Ballard wrote: You don't need an alias; Xcode does indeed want a file reference. Here's the deal:
The short story: The correct statement is: add aFile to aCopy
The long story: The add command takes a file reference. aFile is a file reference, so you can pass that in. Alternatively, you can say something like: tell aProject add file reference "main.m" to aCopy end tell
or, equivalently: add file reference "main.m" of aProject to aCopy
When you do that, the command isn't "(add file reference) 'main.m'...", it's "add (file reference 'main.m')...". Saying "file reference 'main.m' of aProject" will find the file reference with that name in the project; you can also find file references by ID (file reference id '29B97324FDCFA39411CA2CEA' of aProject), position (file reference 1 of aProject), filter (every file reference of aProject whose path is "/System/Library/Frameworks/AppKit.framework"), and a number of other ways. What you did was try to find a file reference using a file reference instead of a name, id, filter, etc. If 'aFile' is currently 'file reference 1 of aProject', then 'add file reference aFile to aCopy' really means 'add (file reference (file reference 1 of a Project) of aProject) to aCopy'.
When AppleScript says that it couldn't "make file reference (item 2 of every file reference of project "Test") into type reference", it meant that trying to specify a file reference using another file reference didn't return something it could use as a reference.
This shouldn't do anything. Are you sure this actually made any change to your project?
To finish off, here's a script that should do what you've described. Note that this uses the "file kind" property of a file reference, which currently does not appear in Xcode's scripting dictionary due to a known bug. The "file kind" property is the same value you see in the "file type" popup in Xcode's file inspector.
tell application "Xcode" set aProject to project 1 set aCopy to copy files phase 1 of target 1 of aProject repeat with aFile in every file reference of aProject if (file kind of aFile is "sourcecode.c.h") or (file kind of aFile is "sourcecode.cpp.h") then add aFile to aCopy end if end repeat end tell
I hope this helps.
- Rick
|