8

I want to launch the browser in iOS Simulator from the Terminal with specified URL.

Is there any command for it? So that I can write in a script which will take URL as argument and launch simulator with browser and URL open on it.

6 Answers 6

9

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/Applications/MobileSafari.app/MobileSafari -u "http://google.com/"

Yes this really is one long command — make sure to run it all. Replace google.com with actual website, and iPhoneSimulator7.0.sdk with the relevant version of the simulator that you're using.

2
  • 1
    You can easily pass in the target website if you replace "http://google.com" with "$*", and you save this as a shell script (e.g. ~/launch_ios_browser.sh, then chmod 700 the file). Then you can go to localhost using ~/launch_ios_browser.sh http://apple.com
    – Brad Parks
    Commented Apr 16, 2014 at 9:53
  • @grgarside Any idea how to do this in the latest Xcode with the iOS Simulator?
    – Stoutie
    Commented Sep 26, 2014 at 17:22
5

On Xcode6 simctl was introduced so you can just open the terminal and type:

xcrun simctl openurl booted "https://google.com"

1
  • Initially I was getting an error (xcrun: error: unable to find utility "simctl", not a developer tool or in PATH) so I needed to launch XCode (Version 11.6 (11E708)) and set the Command Line Tools as in stackoverflow.com/a/36726612/1449799
    – Michael
    Commented Oct 6, 2020 at 19:11
3

The path has changed for Xcode 6.0 (OS X Yosemite) and now it's:

alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app'

0

Another way to do it is to use a temp file that redirects to the URL you want, then opening this file in the simulator. This isn't necessarily the best way, but it is a shorter command.

echo "<meta http-equiv="refresh" content='0;url=http://apple.stackexchange.com'>" > ~/tmp/openURL.html; open ~/tmp/openURL.html -a /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/

As in the other answers, you can replace the URL (I put apple.stackexchange.com) with whatever you want. Just make sure you put http:// because open interprets arguments as filesystem paths by default.

Sadly, the bulk of the command is just the path to the iPhone Simulator bundle.

-1
osascript -e "tell application \"iPhone Simulator\" to activate"
1
  • 1
    This does start the Simulator, but how does it start the browser inside the simulator as well?
    – nohillside
    Commented Jun 23, 2014 at 16:59
-1

Here's what to do : Go to Finder and run /Applications/Utilities/Terminal, and paste in the following code:

open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app

That should help if you use XCODE, or a iOS Simulator.

1
  • This doesn't open to the browser, let alone a specified URL.
    – grg
    Commented Jan 13, 2014 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .