Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can one run a project on multiple destinations (say, iPhone, iPad and iSimulator) at once? Xcode Product optionsXcode multiple destinations


There are 2 related questions:

  1. Xcode 4 - One Click Build to Multiple Devices?
  2. Run on simulator and phone with one click

The 1ˢᵗ question (supposedly) has an answer, but I can't figure out how exactly should you use the Aggregate target (if this is the right direction at all), and apparently neither could Josh Kahane, the OP; the "answer" still somehow got/remained accepted.

The 2ⁿᵈ question was closed down as a "duplicate", as if the 1ˢᵗ one provided a (workable) answer.


Added a bounty: (how) can one use Aggregate target for simultaneous, multiple Build & Run? Perhaps one can achieve simultaneous, multiple Build & Run via some .sh script using xcodebuild? Any other possible solution?

like image 741
Blaz Avatar asked Apr 28 '13 11:04

Blaz


4 Answers

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!

like image 90
kitschpatrol Avatar answered Nov 08 '22 08:11

kitschpatrol


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.

like image 31
Blaz Avatar answered Nov 08 '22 09:11

Blaz


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);
    });
}
like image 45
Ivan Neeson Avatar answered Nov 08 '22 08:11

Ivan Neeson


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

like image 1
TheThibz Avatar answered Nov 08 '22 09:11

TheThibz