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?

Balaji Sekar
  • 3,295
  • 3
  • 16
  • 13

9 Answers9

211

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>

starball
  • 20,030
  • 7
  • 43
  • 238
Balaji Sekar
  • 3,295
  • 3
  • 16
  • 13
  • 8
    is your app bundle id – Hugo Nov 12 '14 at 04:49
  • Not that I saw, other than some [known issues](https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc6_release_notes.html#//apple_ref/doc/uid/TP40001051-CH4-SW1), as mentioned running `xcrun simctl` will list the commands. In my opinion they are pretty self explanatory. – SavoryBytes Dec 04 '14 at 18:39
  • 1
    I wasn't able to get it to work using `xcrun simctl boot ` instead of `xcrun instruments -w...` – CambridgeMike Dec 17 '14 at 00:55
  • 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 booted – Pooja Shah Jan 27 '15 at 12:17
  • very direct and precise to ensure you are working with what was intended. nice work man! – Laser Hawk Sep 22 '15 at 21:45
  • I just used this to install our app on a simulator for our Project Manager. Thanks! – rein Nov 17 '15 at 19:50
  • 2
    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. – devios1 Nov 18 '15 at 19:08
  • 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. – Motti Shneor Feb 17 '19 at 12:04
  • is the same as `Bundle Identifier` in XCode. – GarouDan Jan 26 '20 at 14:11
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>

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • 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. – Michael Teper Jan 12 '15 at 23:37
  • Hmm, we have it reliably not working across 3 different machines. Any other info I can supply to help troubleshoot? – Michael Teper Jan 13 '15 at 00:04
  • 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)? – Michael Teper Jan 13 '15 at 00:42
  • 1
    open /path/to/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app – Jeremy Huddleston Sequoia Jan 13 '15 at 02:16
  • Yup, that's where it lives today (Xcode 6.x). Is it safe to rely on Apple not changing it going forward? – Michael Teper Jan 13 '15 at 06:43
  • Given that it moved in Xcode 6 (see initial question), you should not expect that, but you can easily adapt your script if needed. – Jeremy Huddleston Sequoia Jan 13 '15 at 06:45
  • Thanks, @jeremy. Any chance you could weigh in on this one too: http://stackoverflow.com/questions/27855664/how-to-set-ios-simulator-language-when-launching-via-simctl ? – Michael Teper Jan 13 '15 at 07:24
  • @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! – Chris Conover Feb 22 '16 at 23:12
  • 2
    @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. – Jeremy Huddleston Sequoia Feb 24 '16 at 06:11
  • You can also get the device list here: `~/Library/Developer/CoreSimulator/Devices/device_set.plist ` – Alex Zavatone Jan 13 '17 at 03:42
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

TinyTimZamboni
  • 5,275
  • 3
  • 28
  • 24
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
Javier Rojano
  • 814
  • 9
  • 17
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.

Estevão Lucas
  • 4,440
  • 34
  • 37
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.

Neenu
  • 6,848
  • 2
  • 28
  • 54
  • 2
    Use `instruments -s devices` to get a list of devices. However, once you have the device name, simply calling `instruments -w ` 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. – Michael Teper Jan 13 '15 at 00:11
  • To elaborate on @MichaelTeper's comment, use `-D` to specify an output directory for the .trace documents. – devios1 Nov 19 '15 at 18:53
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.

Alex Zavatone
  • 4,106
  • 36
  • 54
  • 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). – Motti Shneor Feb 14 '19 at 16:04
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
gvlasov
  • 18,638
  • 21
  • 74
  • 110
  • iOS-sim (including the humungous Node) must be installed for this, and it is sadly limited, compared with the native command line 'scrub simctl'. – Motti Shneor Feb 17 '19 at 12:32
0

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

open -a simulator
Cito
  • 26
  • 6