0

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.

keyboard
  • 2,137
  • 1
  • 20
  • 32

1 Answers1

1

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
jackjr300
  • 7,111
  • 2
  • 15
  • 25
  • Wow that was fast and it's awesome! Thank you! Do you by chance also know to run on a specific device? I'm making a real-time multiplayer game and I often need to run on two devices. It'd be cool to run on one device, wait until it's done, then run on the other. – keyboard Sep 01 '17 at 15:50