How to 'Build & Run' on multiple destinations at once in Xcode?

It would indeed be nice to have multiple uploads at once with Xcode. However as I understand it, aggregate only allows you to compile multiple targets, not run them.

Given the second part of you question (after the edit) I can point you to another way to do it. You won't have xcode attached (but gdb in console mode) and you should be able to make it simultaneous on several device, although this was not the primary goal. This particular solution doesn't work with simulator, but there are other methods for those.

launching iOS App from Mac OS X console


Here is a script that will build and run on all connected iOS devices. To use:

  1. Open "Automator".
  2. Create a new "Quick Action".
  3. Select "no input" for "Workflow receives".
  4. Select Xcode for the application.
  5. Add a "Run JavaScript" action and paste the script.
  6. Save as "Run on All", you can now access this from the Xcode -> Services menu from Xcode.

Javscript:

function run(input, parameters)
{
    var xcode = Application("Xcode");
    var ws = xcode.activeWorkspaceDocument();
    var genericDest = null;
    var devices = [];
    ws.runDestinations().forEach(function(runDest)
    {
        if (runDest.platform() != "iphoneos")
            return;
        if (runDest.device().generic())
        {
            genericDest = runDest;
        }
        else
        {
            devices.push(runDest);
        }
    });
    devices.forEach(function(device)
    {
        ws.activeRunDestination = device;
        var buildResult = ws.run();
        while (true)
        {
            if (buildResult.completed())
                break;
            if (buildResult.buildLog() && buildResult.buildLog().endsWith("Build succeeded\n"))
                break;
            delay(1);
        }
        delay(1);
    });
}

It's actually simpler than I thought. This AppleScript puts some pain out of Xcode:

tell application "Xcode"
    activate
end tell

tell application "System Events"
    tell application process "Xcode"
        click menu item "1st iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
        click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
        delay 5
        click menu item "2nd iDevice Name" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1
        click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
        delay 5
        click menu item "iPhone 6.1 Simulator" of menu 1 of menu item "Destination" of menu 1 of menu bar item "Product" of menu bar 1            
        click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
    end tell
end tell
  1. Save the above AppleScript as an .app. (Customize delays to your machine.)
  2. Create a new Service in Automator: choose Launch Application and select the .app from previous step.
  3. Save Service from previous step and give it a keyboard shortcut. Tip: avoid shortcuts with ^, since it will bring up this dialog: enter image description here

Granted, this isn't strictly a simultaneous 'Build & Run', but it sure beats manually trifling between destinations.


I ran into the same issue, so I wrote an Xcode plugin to help out with this. I found it to be more robust and easier to invoke than the AppleScript options.

The plugin is called KPRunEverywhereXcodePlugin and is available via Alcatraz or on GitHub: https://github.com/kitschpatrol/KPRunEverywhereXcodePlugin

New menu items

Hope this helps!