• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using AppleScript to access a Copy File Phase in an Xcode project
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Thu, 22 Sep 2005 20:14:03 -0700

You don't need an alias; Xcode does indeed want a file reference. Here's the deal:

On Sep 21, 2005, at 11:37 AM, Dave McCaldon wrote:

Thanks for the help, I almost have it working now.  I'm getting what is probably a regular AppleScript error, but I'm just not [yet] familiar enough with AppleScript to figure it out:

"Xcode got an error: Can't make file reference (item 2 of every file reference of project "Test") into type reference."

The line of code in question is:

        add file reference aFile to aCopy

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.

On Sep 21, 2005, at 4:35 PM, Dave McCaldon wrote:

Ok -- the files I'm adding are already in the project.  Basically, I'm trying to automate the creation of a framework by locating *all* .h files and copying them into the Headers directory within the framework, but taking into account the subdirectory-ness of them so that current code still works.

It seems that the Copy Files Phase instance only maintains a collection of build files, not file references.  If you look at build file, you'll see that it has a file reference.  So I'm assuming that I need to create a "build file" instance and set it's file reference.

This is true; build phases contain build files, and every build file has a file reference. This is why you can't move or copy a file reference to a build phase using the standard applescript commands. Xcode's add command does the right thing for you, though; when you tell Xcode to add a file reference to a build phase, it actually creates a new build file in the phase which uses your file reference.

On Sep 22, 2005, at 4:20 PM, Daniel Jalkut wrote:

I was able to get this simple test working on one of my projects:

tell application "Xcode"
    set myFile to file reference "/Users/daniel/Sources/FastScripts/main.m" as POSIX file
    set myAlias to myFile as alias
    set myPhase to (build phase 2 of target 1 of project 1)
    add myAlias to myPhase
end tell

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
 _______________________________________________
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

  • Follow-Ups:
    • Re: Using AppleScript to access a Copy File Phase in an Xcode project
      • From: Daniel Jalkut <email@hidden>
    • Re: Using AppleScript to access a Copy File Phase in an Xcode project
      • From: Dave McCaldon <email@hidden>
References: 
 >Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Daniel Jalkut <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Gouri jonnalagadda <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Gouri jonnalagadda <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Daniel Jalkut <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Dave McCaldon <email@hidden>)
 >Re: Using AppleScript to access a Copy File Phase in an Xcode project (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Using AppleScript to access a Copy File Phase in an Xcode project
  • Next by Date: Re: Is there an XCode Apple Event for New Project...?
  • Previous by thread: Re: Using AppleScript to access a Copy File Phase in an Xcode project
  • Next by thread: Re: Using AppleScript to access a Copy File Phase in an Xcode project
  • Index(es):
    • Date
    • Thread