Easily launch the iOS Simulator from the command line

Launching the iOS Simulator is easy to do when we have a project already loaded in Xcode, Xamarin Studio, or Visual Studio. Simply run the project, and the iOS Simulator will automatically launch.

There are other times, though, when it would be nice to quickly launch the simulator to test something out, or maybe run an existing app. Xcode includes simctl to control the simulator, but there is an even easier way.

The ios-sim project from Phonegap provides a very nice command line interface to control the simulator

"The ios-sim tool is a command-line utility that launches an iOS application on the iOS Simulator. This allows for niceties such as automated testing without having to open Xcode." - ios-sim repository

We can easily install ios-sim using npm:

npm install ios-sim -g  

Make sure to explore the API once it's installed. In order to launch a simulator, we can open terminal and run:

ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus  

To make this even easier, I have created aliases in my ~/.bash_profile file for the common iOS devices I use:

alias iPhone4s="ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-4s"  
alias iPhone5s="ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-5"  
alias iPadAir="ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPad-Air"  
alias iPhone6Plus="ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"  
alias iPhone6="ios-sim start --devicetypeid com.apple.CoreSimulator.SimDeviceType.iPhone-6"  

Now, launching a simulator is as easy as typing iPhone6Plus