I want to launch iPhone simulator from command line.
until now I have been using the below command
/Applications/Xcode.app/Contents/Developer
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
For xcode 7:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID <DeviceUDID>
Get your simulator udid's from xcrun simctl list
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>
Hope this helps.
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>
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.
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.