A fast zsh prompt that packs in a lot of Git status info
A version of this article appeared on viget.com
Read More
This article is the first in a two-part series on running cross-browser tests directly on your primary computer. The second is Set Up a Windows 10 Virtual Machine and Run Internet Explorer 11 and Edge on Mac or Linux.
Part of preparing most websites and web apps for shipment is testing across devices. Several popular web-based browser testing services make it possible to test iOSâs Mobile Safari, but the best of these tools require an additional fee, have limited free features, or restrict the number of users who can use an account at the same time. Apple makes iOS testing available for free to all macOS users, with their Simulator app. The app is hidden away and you need to go through some hoops to support older versions of iOS, but you donât need special technical know-how. Hereâs how to get it up and running with just a few clicks (and some longish download waits). It works for watchOS and tvOS as well!
First install XCode, Appleâs developer suit. Be prepared for a long download.
Simulator is a standalone app but itâs buried deep within the hidden contents of XCode, where you canât get at it, and where Spotlight doesnât see it. So make a symbolic link of it in the Applications folder. Hereâs how, in case you donât know:
Open Terminal (in the Applications folder) or your favorite terminal app
Run this (not comfortable? skip down to the Addendum for an explanation):
shellln -s Applications/Xcode.app/Contents/Developer/Applications/Simulator.app Applications
shellln -s Applications/Xcode.app/Contents/Developer/Applications/Simulator.app Applications
Open Simulator (double click it from the Applications folder, or open it from Spotlight, or if youâre psyched about flexing new-found command line powers run âtype and follow with the Enter â keyâ the command open /Applications/Simulator.app).
Look at that! An iOS device!
Now you can click on the Safari icon and start browsing! But read on to get the most out of SimulatorâŚ
With the devices you need all installed, letâs get to know Simulator a little. Weâll change the window size, add support for your computer keyboard, and add support for trackpad scrolling.
By default, you have to use the on-screen keyboard to type in Simulatorâs iOS devices, just like you use the on-screen keyboard on a real iOS device. But you can turn on support for your physical keyboard:
In Simulatorâs âHardwareâ menu, under âKeyboard,â check âConnect Hardware Keyboard.â
By default, the standard command v keyboard shortcut will not work to paste to Simulator from any other app. To turn on the shared clipboard (known in Apple devices as the pasteboard), select âAutomatically Sync Pasteboardâ from the âEditâ menu.
Note for users running older versions of Xcode: This worked differently prior to Simulator 10. Youâll have to use shift command v to paste the macOS clipboard into the Simulator pasteboard, and then you can use command v to paste from the pasteboard.
With Simulator you can test any Apple device. Select the device you want to use from the âDeviceâ submenu in the âHardwareâ menu. By default youâll have only the latest version of iOS, tvOS, and watchOS, but you can easily install âruntimesâ for older versions.
To add support for other versions of iOS, tvOS, or watchOS, first select âManage Devicesâ from the the âHardwearâ menuâs âDeviceâ submenu. (For iOS marketshare by version, refer to ~iOS Distribution and iOS Market Share~ (tool no longer available) or Mobile & Tablet iOS Version Market Share Worldwide. Historically, the most recent and second most recent versions of iOS account for between 80â90% of iOS usage, with adoption of the most recent version taking several months to surpass the second most recent version.)
That will open the Xcode appâs âDevicesâ window. Select the âSimulatorsâ tab. Then click the + in the bottom left corner. (Note that your window may look different â as of this writing, it has been redesigned in every recent version of XCode. In XCode 9 youâll have to select âAdd Deviceâ from the +'s contextual menu).
Under âOS Version,â select âDownload more simulator runtimes.â
Another new window opens, Xcodeâs âComponentsâ preferencesâ list of simulators. Click the downward arrow button next to the OS you want to install support for.
When the download is complete, close the window. Back in the âCreate a new simulatorâ dialog:
Click âCreate,â and quit Xcode. Back in Simulator, the device you just added should show up in the âDevicesâ list!
There you have it! If you arenât familiar with the command line and want to understand what the symbolic link command was doing, continue down to the addendum. Otherwise, youâre set up to test things on iOS without going through some extra service!
By default, you can scroll in a Simulator device by clicking and dragging. With the hardware keyboard connected, you can also use the keyboard arrow keys. If youâre used to using trackpad scrolling (e.g. two-finger scrolling) in macOS, you may want to turn it on for Simulator too. While two-finger dragging isnât supported, three-finger dragging is. As of this writing, the experience really isnât good: there can be a initial delay, and then another delay before inertial scrolling kicks in. Hereâs how to turn it on:
From the System menu () open the âSystem Preferences,â and from there, open the âAccessibilityâ preferences. Under âMouse & Trackpad,â open the âTrackpad Optionsâ and turn on âthree finger drag.â
Sometimes itâs useful to have two devices up on the screen at the same time. Before, Xcode 8 (or was it 9?) Simulator could only run one device at a time. If youâre on an older version of Simulator that doesnât support multiple devices, you can open two instances of the Simulator app with open -n:
shellopen -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.appopen -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
shellopen -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.appopen -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
The second instance of the app opens with an error âUnable to boot device in current state: booted.â Thatâs saying âthe device youâre asking to simulate is already being simulated,â which is true â by default itâs trying to open the same device as itâs running in the first instance of the app. Say OK, then go to the Hardware menu > Device and choose a different device. (h/t i40west for the technique)
If you arenât familiar with the âcommand line,â donât just run a command because someone on the internet says to. I donât know if itâs ever really happened (it probably has), but there are plenty of urban legends of command line novices getting tricked into doing serious damage to their computers.
Iâve said that to make Simulator appear you run
shellln -s /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app /Applications
shellln -s /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app /Applications
In a nutshell, the Simulator app is installed as part of Xcode, but itâs hidden. So we create an alias (aka âshortcutâ to people who learned the term on Windows) to the hidden app, and put the alias in the Applications folder.
Hereâs how it works:
The âcommand lineâ lets you run programs that donât have an interface â you tell the app what to do with text commands rather than by clicking on things. The first thing you write is the name of the command. Here, weâre running ln, a command that creates links, the technical name for aliases (ln is short for âlinkâ).
Next, write the command-specific options. Option are set with âflagsâ prefixed with -. lnâs -s flag turns on lnâs âsymbolic linkâ option. There are important differences between symbolic links and plain old links, but in this context what matters is that apps cannot be aliased with a link; apps must be aliased with a symbolic link.
The next thing ln needs to be told is the thing you want to create an alias to (the âsource fileâ). All files on your computer have an address, written in the form folder/subfolder/file where in a/b/c âcâ is inside âbâ which is inside âaâ. This should look familiar from website URLs, and itâs actually exactly the same: a websiteâs URL reflects an actual folder structure on a computer somewhere. [More or less⌠That used to be a given; now itâs only sometimes mostly true.] In our case, Xcode is in the âApplicationsâ folder, and inside Xcode thereâs a Contents folder, and in that is a Developer folder, and in that is an Applications folder, and the Simulator app is in that.
Next you specify the place ln should put that alias (the âtarget directoryâ). It makes sense to put your alias to Simulator in the âApplicationsâ folder: add a space after the source fileâs path, and then write /Applications. (See that / in front of /Applications, in both the source file and the target directory? Thatâs saying âthis is at the top levelâ - Xcode is a child of âApplicationsâ but âApplicationsâ is not the child of anything. One last bit of vocab: âApplicationsâ is the parent of Xcode.)
Okay, hit Enter!
Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme
A fast zsh prompt that packs in a lot of Git status info
Fundamental Twig for Front-End Development
Your comprehensive guide for Twig front-end view templates.
Fundamental ERB for Front-End Development
Your comprehensive guide for ERB front-end view templates.