views:

602

answers:

3

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?

+1  A: 

Unless you really want the Xcode GUI, you could just use xcodebuild instead of launching and scripting Xcode.

smorgan
I know about xcodebuild, but I wanted to get this to work in the GUI, mainly because of the error list that brings you to the line of the error when double-clicked.
Michael
A: 

I use:

osascript -e 'tell application "Xcode"
    activate

    set targetProject to project of active project 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)

Harry Jordan
A: 

And for other TextMate users out there, a cobbled together.. improved version by mashing it together with the existing 'Open project in Xcode..' command:

PROJECT=$(ruby -- "${TM_BUNDLE_SUPPORT}/bin/find_xcode_project.rb")
if [[ -f "${PROJECT}/project.pbxproj" ]]; then
   open -a Xcode "${PROJECT}"
else
   echo "Didn't find an Xcode project file."
   echo "You may want to set TM_XCODE_PROJECT."
fi


osascript -e 'tell application "Xcode"
    activate

    set targetProject to project of active project document
    if (build targetProject) is equal to "Build succeeded" then
     launch targetProject
    end if
end tell'
Harry Jordan