Xcode Run from Other App / Command Line / Apple Script

432 views Asked by At

Is it possible to have Xcode in the background but compile and run the current project via a Script?

I'm mainly using AppCode for development, but would like to run from Xcode through a hotkey. AppCode does not properly show a compilation-progress bar (Xcode on second screen can), also AppCode's debugging abilities are not as advanced as Xcode's. Otherwise AppCode is faster and better.

1

There are 1 answers

1
jackjr300 On BEST ANSWER

It's possible from an AppleScript, here's a sample script (tested on Sierra and Xcode Version 8.3.3):

tell application "Xcode"
    tell active workspace document to if exists then
        repeat until (loaded) -- Whether the workspace document has finished loading after being opened
            delay 1
        end repeat
        run -- Invoke the "run" scheme action
    end if
end tell

To run on a specific device: I don't have devices to test, but I use the simulator, try this script:

tell application "Xcode"
    tell active workspace document to if exists then
        repeat until (loaded) -- Whether the workspace document has finished loading after being opened
            delay 1
        end repeat
        --**** run on a specific device ****
        set active run destination to run destination "iPad Pro (12.9 inch)" -- *** change it to the name of your device  ***

        set schAction to run -- Invoke the "run" scheme action
        repeat while (get status of schAction) is in {not yet started, running} -- exit the loop when the status is (‌cancelled, failed, ‌error occurred or ‌succeeded), so I press the stop button in Xcode, or I delete the application in the simulator or I quit the simulator.
            delay 3
        end repeat

        --**** run on another specific device ****
        set active run destination to run destination "iPhone 7" -- *** change it to the name of your device  ***
        run
    end if
end tell