13

The following are the steps I would like to have:

  1. launch xcode
  2. open a specific xcodeproj file
  3. build and debug it
  4. quit xcode

The following is my first attempt to write AppleScript:

tell application "Xcode"
    tell project "iphone_manual_client"
        debug
    end tell
    close project "iphone_manual_client"
end tell

This only works when xcode has this project opened. I would like to have the project to be opened only when it is necessary to do so.

Can any AppleScript gurus out there points me to the right direction? Thanks.

-chuan-

chuan
  • 813
  • 1
  • 6
  • 20

4 Answers4

13

I think I managed to solve it. The following is the AppleScript:

tell application "Xcode"
    open "Users:chuan:Desktop:iphone_manual_client:iphone_manual_client.xcodeproj"
    tell project "iphone_manual_client"
            clean
            build
            (* for some reasons, debug will hang even the debug process has completed. 
               The try block is created to suppress the AppleEvent timeout error 
             *)
            try
                debug
            end try
    end tell
    quit
end tell

The path has to be in format of ":" instead of "/". The only problem now is that after the debug console has done its job, AppleScript seems to "hang" as though waiting for something to happen. I need to do more research on AppleScript to know what is wrong with the script.

chuan
  • 813
  • 1
  • 6
  • 20
  • do you know how to check if debug is already running? I'm getting an issue on subsequent executions of my script: "Unable to debug executable since a debug session is in progress" – Aaron McAdam Jan 06 '11 at 12:41
  • Hi Aaron, I supposed another option is to force XCode to shutdown completely and launch XCode again before running your new set of tests? This might get around the problem you are facing. – chuan Jan 20 '11 at 13:22
  • 3
    Unfortunately a lot of Xcode AppleScript functionality was broken with Xcode 4, including the run and debug features. It looks like the script above no longer works. – ThomasW Feb 06 '12 at 09:41
  • You must remove `project` word in `tell project` command. – Velcro Jan 09 '23 at 09:59
4

I'm not sure about AppleScript but you can compile it from command line, without opening xcode ide, like this:

xcodebuild -configuration Debug -target WhatATool -project WhatATool.xcodeproj

Where configuration is obvious option, target is the name in Target list of xcode and the project name at the end.

stefanB
  • 77,323
  • 27
  • 116
  • 141
  • 2
    Hi stefan, thanks for your response. This will build the application. The reason why I need to use xcode is the uploading and remote debugging mechanism it has for iphone. There is no command line tool that I can use to let me upload my newly compiled iphone app to the real device easily apart from xcode. – chuan Jun 17 '09 at 13:52
2

There's a command line utility called xcodebuild (man page here) which may work better for what you want to accomplish.

pgb
  • 24,813
  • 12
  • 83
  • 113
  • 1
    Hi pgb, xcodebuild will only build it for me. It does not help me to upload the app to iphone and debug it from there. – chuan Jun 17 '09 at 13:53
2

Since debugging can take an arbitrary amount of time, you probably want a "with timeout of seconds" / "end timeout" block around the debug message.

cdespinosa
  • 20,661
  • 6
  • 33
  • 39