Re: Using AppleScript to access a Copy File Phase in an Xcode project
Re: Using AppleScript to access a Copy File Phase in an Xcode project
- Subject: Re: Using AppleScript to access a Copy File Phase in an Xcode project
- From: Rick Ballard <email@hidden>
- Date: Wed, 28 Sep 2005 21:35:02 -0700
It turns out that this is a bug in Cocoa scripting; thank you for
reporting this. The problem occurs with statements like "add aFile to
item 1 of copy files phases of aTarget", but not with statements like
"add aFile to copy files phase 1 of aTarget", even though the
statements should be equivalent.
"repeat with aCopy in every copy files phase of aTarget" sets aCopy
to be equal to "item x of every copy files phase of aTarget" instead
of "copy files phase x of aTarget", so you're encountering the same
problem with the repeat loop in your _locateCopyPhase() handler.
Until this bug is fixed, you can work around the problem by rewriting
your repeat loop like so:
repeat with copyIndex from 1 to count of copy files phases of aTarget
set aCopy to copy files phase copyIndex of aTarg
if ((destination directory of aCopy) is equal to wrapper) and ((path
of aCopy) is equal to ("Headers/" & aDir)) then
return aCopy
end if
end repeat
- Rick
On Sep 28, 2005, at 5:38 AM, Dave McCaldon wrote:
Actually, it already is in a separate variable, the code I pasted
was from the event log, what I actually do is this:
add aFile to aCopy
If it's easier, here's the actual code is below. I call
_updateCopyPhaseFileReference for each header file I find in the
project.
Thanks.
(*
The _locateCopyPhase handler searches the target given by
aTarget for a matching
copy files build phase.
The matching is done by comparing the path and the destination
directory.
*)
on _locateCopyPhase(aTarget, aDir)
tell application "Xcode"
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
end if
end repeat
end tell
return null
end _locateCopyPhase
(*
The _updateCopyPhaseFileReference handler searches for a Copy
Files phase for the
specified directory, creating one if necessary.
It then adds the specified file reference to the copy step.
*)
on _updateCopyPhaseFileReference(aProject, aTarget, aDir, aFile,
aName)
local aCopy
set aCopy to my _locateCopyPhase(aTarget, aDir)
tell application "Xcode"
if aCopy is not null then
-- Check to see if we already have this header in this
copy file step
repeat with aBuildFile in every build file of aCopy
if (full path of (file reference of aBuildFile)) is
equal to (full path of aFile) then
-- Already here, we don't need to add it
log "*** SKIP: ignoring " & aName & " because
it's already here"
return false
end if
end repeat
else
-- Need to create a new Copy Files build phase
log "*** NEW: Creating new Copy Files Phase for:
Headers/" & aDir
tell aTarget
set aCopy to make new copy files phase with
properties {destination directory:wrapper, path:"Headers/" & aDir,
run only when installing:false, comment:""}
-- add aCopy to aTarget
end tell
end if
if (target of aCopy) is not equal to aTarget then
display dialog "target mismatch " & (target of aCopy) &
" vs " & aTarget buttons {"OK"} default button 1
end if
-- Make a new reference
-- display dialog "Adding file reference " & (project
relative path of aFile) & " to " & (path of aCopy) buttons {"OK"}
default button 1
log "*** ADD: Adding file " & aName & " to " & aDir & "
aCopy is: " & (destination directory of aCopy) & "/" & (path of
aCopy) & ":" & (class of aCopy)
add aFile to aCopy
-- display dialog "Added " & (project relative path of
aFile) buttons {"OK"} default button 1
return true
end tell
end _updateCopyPhaseFileReference
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden