Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 753
Michael Avatar asked Jul 08 '09 21:07

Michael


2 Answers

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)

like image 123
Harry Jordan Avatar answered Oct 17 '22 00:10

Harry Jordan


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

like image 39
smorgan Avatar answered Oct 17 '22 00:10

smorgan