views:

41

answers:

2

I have a tedious task that I need to repeat every time I build my iPhone project for sending to non-programmer colleagues: all libraries and headers that I reference outside the project's folder need to be copied into the project folder or a subfolder thereof, so I can zip up the source and pass it on.

I'm aware that you can automate XCode with AppleScript, but I can't for the life of me find any proper documentation of the commands available. If I google XCode AppleScript automation, I just get a bunch of hits on writing AppleScript apps in Xcode.

Any help will be greatly appreciated!

A: 

based on your description, it would be easier to create a custom target in xcode to perform this task. xcode can run all sorts of unix utilities for copying, zipping, etc. soo... shell scripting should be much easier. you can also set this target up as a dependency if you'd like, so it always stays up to date (but a little slow for regular development, tbh.

yeah, you can use applescript with xcode in many cases, but it is going to be much more difficult for the task you've outlined.

Justin
Shell scripts are fine for copying files etc, but in this case I need to change the project's file references as well. For instance, if the project references ../SomeOtherProject/SomeFile.mm, that needs to become SomeFile.mm after the file is copied.
Jonny Boy
ah - ok, i misunderstood what you meant by your original post. i thought you were referring to the references files, not the project references as well. ok - we don't generally go through all these tedious steps in delivery. in some cases, you can just use a search and replace in the xcode project file itself. it would be easier if you just added search paths (for inclusions), or used xcode's 'Source Trees' to change the references/search paths (for files you must compile).
Justin
Source Trees are pretty sweet, didn't know about that. They don't solve my problem though. I could do a search + replace, just feels a bit hacky. I know there are commands to manipulate an xcode project through AppleScript (including adding/removing references etc), I just can't find any docs on it. :-/ Thanks for your help though!
Jonny Boy
Ah, found it! In AppleScript Editor, select File -> Open Dictionary -> Xcode.
Jonny Boy
A: 

here's a demo to get you started. since you know how to locate the dictionary, the rest may be easy if you are comfortable using AppleScript:

tell application "Xcode"
    -- of course, use your project's name instead of Alias
    set projectName to "Alias" 
    set xcProject to project projectName

    repeat with idx from 1 to the count of (get every file reference of xcProject)
        set fileRef to (file reference idx) of xcProject
        get path of fileRef
        get id of fileRef
        get name of fileRef
        get properties of fileRef

        set newPath to path of fileRef
        -- add logic and alterations here
        set path of fileRef to newPath
        -- ...
    end repeat
end tell
Justin