xcodeapplescript

How to build & run Xcode with Applescript?


I'm trying to emulate Xcode's ⌘-R keystroke in another editor (namely, Vim); I thought I would be able to do this with some shell scripting & applescript, but it doesn't seem to be working correctly:

open -a Xcode "MyProj.xcodeproj"
osascript -e 'tell app "Xcode"' -e 'build' -e 'launch' -e 'end tell'

The problem with this is it launches the app regardless of whether Xcode reports errors. Is there any way to fix this?


Solution

  • I use:

    osascript -e 'tell application "Xcode"
        activate
    
        set targetProject to active workspace document
        if (build targetProject) is equal to "Build succeeded" then
            launch targetProject
        end if
    end tell'
    

    Of course, the project has to already be open in Xcode for this to work. (I'd rather not hard code the current project into my script)