Xcode 6 - Launch simulator from command line
Asked Answered
N

9

104

I want to launch iPhone simulator from command line.

until now I have been using the below command

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator -SimulateDevice

-SimulateDevice is used to launch a specific device type

Now with Xcode 6 the path and the app has been changed to

/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app/Contents/MacOS/iOS Simulator

but sadly -SimulateDevice option is not working now. I can launch the simulator, but dont have an option to specify which one to launch

Anyone found any alternatives for this with Xcode 6?

Noreen answered 25/9, 2014 at 5:57 Comment(0)
N
210

Found a way to achieve what I wanted.

Apple has introduced an interesting tool with Xcode 6!

simctl

simclt allows you to control the simulator that are running.

run xcrun simctl to get the list of available subcommands. Lots of new options to play around with.

Now to do what I wanted, here is the command to launch the simulator:

xcrun instruments -w "iPhone 5 (8.0 Simulator)"

-w is to provide a device type and to get the list of available devices.

Just execute this:

xcrun instruments -s

After launching the simulator you can control it using simctl

To install your app:

xcrun simctl install booted <app path>

To launch the app:

xcrun simctl launch booted <app identifier>

Noreen answered 25/9, 2014 at 7:14 Comment(9)
<app identifier> is your app bundle idDelorisdelorme
Not that I saw, other than some known issues, as mentioned running xcrun simctl will list the commands. In my opinion they are pretty self explanatory.Candycecandystriped
I wasn't able to get it to work using xcrun simctl boot <device id> instead of xcrun instruments -w...Windmill
somehow i'm keep getting : simctl[23846:459252] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] on simctl install bootedHagiarchy
very direct and precise to ensure you are working with what was intended. nice work man!Laureenlaurel
I just used this to install our app on a simulator for our Project Manager. Thanks!Moradabad
You should specify the actual device UDID or name rather than booted as booted will just arbitrarily choose one of the booted devices on the simulator.Niel
for the newbs, it may be helpful to say that all these nice commands ought to be run in the Terminal, assuming both Xcode and Xcode command-line-tools are installed.Vagrant
<app identifier> is the same as Bundle Identifier in XCode.Abridge
G
65

With Xcode 6, if you want to have the iOS Simulator.app boot a specific device when it launches, you can run this from the command line:

open -a "iOS Simulator" --args -CurrentDeviceUDID <DEVICE UDID>

where you can figure out the UDID of the device you want to boot from:

xcrun simctl list

With Xcode 7, the application was renamed Simulator.app, so you should update the above accordingly to:

open -a Simulator --args -CurrentDeviceUDID <DEVICE UDID>

Gifu answered 26/9, 2014 at 6:2 Comment(10)
In 6.2 beta, that command no longer works. For example, instead of launching the iPhone 5s simulator (given its ID), I get the iPad Air simulator.Sectarianize
Hmm, we have it reliably not working across 3 different machines. Any other info I can supply to help troubleshoot?Sectarianize
I've figured out what is happening. We installed Xcode 6.2 beta, but did not make it the default Xcode. So, /usr/bin/xcrun simctl list lists the simulators available to regular Xcode. However, open -a "iOS Simulator" launches the 6.2 beta simulator, which is expecting the device IDs from the beta simulator. How can I specify which simulator I launch (regular vs. beta)?Sectarianize
open /path/to/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.appGifu
Yup, that's where it lives today (Xcode 6.x). Is it safe to rely on Apple not changing it going forward?Sectarianize
Given that it moved in Xcode 6 (see initial question), you should not expect that, but you can easily adapt your script if needed.Gifu
Thanks, @jeremy. Any chance you could weigh in on this one too: #27856164 ?Sectarianize
@JeremyHuddlestonSequoia Can you point us to the documentation for the arguments for this (like CurrentDeviceUDID)? And have you figured out how to configure this with the user-friendly device name ala instruments -w 'iPhone 6'? Thanks!Blowfish
@chrisco There is no documentation. You can check the defaults via defaults read com.apple.iphonesimulator and can override any of those on the command line. Simulator.app uses only the UDIDs to uniquely identify the devices. You cannot use the name.Gifu
You can also get the device list here: ~/Library/Developer/CoreSimulator/Devices/device_set.plist Cortisol
L
17

For xcode 7:

open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID <DeviceUDID>

Get your simulator udid's from xcrun simctl list

Legra answered 18/9, 2015 at 20:20 Comment(0)
B
13

To launch a simulator with a specific device booted I´m using list devices subcommand to get the list of all devices available

$ xcrun simctl list devices
== Devices ==
-- iOS 11.2 --
iPhone 5s (E3B6EA43-C805-49C2-9502-A44A465D8DF2) (Shutdown)
iPhone 6 (801E9E11-CA86-473A-9879-4B0742B827FB) (Shutdown)
iPhone 6 Plus (24013349-1A6F-489C-9A68-ABB00EBB4BBF) (Shutdown)
iPhone 6s (1A594D75-146C-4BEA-A250-1FADE7886114) (Shutdown)
iPhone 6s Plus (C2730FA0-11CB-49C9-A087-CB3C1BF1CC3D) (Shutdown)
iPhone 7 (F58B3749-3276-49E5-81C8-EBA1AEA7B242) (Shutdown)
iPhone 7 Plus (98167D8C-8F27-404C-AB02-588D9AAFD071) (Shutdown)
iPhone 8 (96322368-F763-4E0A-8576-ADE9F678211F) (Shutdown)
iPhone 8 Plus (E916D1EE-B67B-4C01-B3F5-C5C80CC4CDF8) (Shutdown)
iPhone SE (ABEFEDDF-7A7C-4B94-9E91-E065170FA47F) (Shutdown)
iPhone X (84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31) (Shutdown)
iPad Air (DCD8CF4B-2C9F-4BA1-952A-ACB9CAD0A84D) (Shutdown)
iPad Air 2 (A47C9A05-233F-450F-9A39-318258E9ADEA) (Shutdown)
iPad (5th generation) (819C058E-64AC-4E73-8F41-2C0F919F8B56) (Booted)

this command will output a list of available devices with its UDIDs and statuses

Then I launch the simulator app specifying a device with the -CurrentDeviceUDID option

/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <DEVICE-UDID>

NOTE: replace the with a valid UDID from the list.

For example, if we want to launch the simulator with an Ipad (% generation booted):

/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID 84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31

UPDATE 23/05/2018

With Xcode 9.3 CurrentDevice UDID option is not working for me, as a workaround, I have to use simctl to boot the device in the simulator before open it.

xcrun simctl boot 2BF01FC0-7E29-4AF1-ADD1-886DF129A9A9
open -a Simulator 

You can create, erase, delete, boot, shutdown and upgrade simulators using simctl.

$ xcrun simctl create
Usage: simctl create <name> <device type id> <runtime id>

$ xcrun simctl delete
Usage: simctl delete <device> [... <device n>] | unavailable

To get the list of valid device types and runtimes

xcrun simctl list devicetypes

xcrun simctl list runtimes
Barringer answered 27/3, 2018 at 15:48 Comment(0)
M
13

To boot a simulator:

xcrun simctl boot "iPhone X"

It will boot as a headless mode. To make the simulator visible:

open -a Simulator

xcrun simctl boot is simpler than xcrun instruments -w. instruments requires the full device name.

Mow answered 15/4, 2019 at 18:57 Comment(0)
N
8

You can specify the hardware and iOS version with -w flag. The format is

instruments -w "simulator-version"

For eg:

instruments -w "iPhone Retina (3.5-inch) - Simulator - iOS 7.1".

You will get the available hardvare-iOS combinations by using the instruments -w help command.

Nl answered 25/9, 2014 at 9:3 Comment(2)
Use instruments -s devices to get a list of devices. However, once you have the device name, simply calling instruments -w <device> will likely yield an error as instruments attempts to write a trace to the root of your drive. You may want to specify a path for the trace that it will successfully write to.Sectarianize
To elaborate on @MichaelTeper's comment, use -D to specify an output directory for the .trace documents.Niel
C
3

Verified in Xcode 9.4.1

Device list in a REALLY NICE FORMAT: ~/Library/Developer/CoreSimulator/Devices/device_set.plist

Root
    DefaultDevices
        com.apple.CoreSimulator.SimRuntime.iOS-8-4
             com.apple.CoreSimulator.SimDeviceType.iPad-Retina : AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4

Then you want to run (open) your Simulator app and make sure that a new instance of the app is launched.

The app is here: /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app

And the format you'd use is like this:

open -n -a <SimulatorPath> --args -CurrentDeviceUDID <SimDeviceTypeUDID>

So, if I wanted to launch the Simulator above, I'd do this.

open -n -a /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4

Hot damn! I just tested it and it works on Mac OS 10.11.6. Now the next trick is telling the Simulator to open our installed app. I'm not there yet. Hope this helps. Thanks to https://stackoverflow.com/users/726106/jeremy-huddleston-sequoia for his detailed explanation.

Cortisol answered 13/1, 2017 at 3:54 Comment(1)
There is no such thing as "new instance of the app". On Macintosh, an application has but one instance, per logged-in user. This single-instance app, hosted as a single process - can by itself host many "documents" (in this case - simulators).Vagrant
H
1

Run this command. The app will be restarted followed by changes. No need to rebuild it again.

ios-sim "launch" "/Library/WebServer/Documents/testapp/build/iphone/build/Debug-iphonesimulator/test.app" "--devicetypeid" "iPad-2" "--exit";

For devicetypeid list:

ios-sim showdevicetypes
Hebdomadal answered 25/9, 2015 at 13:21 Comment(1)
iOS-sim (including the humungous Node) must be installed for this, and it is sadly limited, compared with the native command line 'scrub simctl'.Vagrant
O
0

Anyone having this issue, this command will open the ios simulator from command prompt

open -a simulator
Omniumgatherum answered 24/6, 2021 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.