Unfortunately I had such a problem, and unfortunately, I didn’t realise that as I was running my code from an icon that I’d added to the home screen, Nathan’s script wouldn’t work for me. All I’d get was the error “Mobile Safari.app must be running in the Simulator to enable the remote inspector.”

A bit of debugging and one “man grep” later, I’d got a solution, and it’s pretty easy: modify the parameter passed to grep to look for “Web.app” as well as “MobileSafari”. There are many ways that this particular cat could be skinned, but I opted for a very straightforward locigal OR in the regular expression:

grep"MobileSafari|Web.app"

I’m fairly good with regular expressions, so couldn’t work out why my pipe character (“|”) wasn’t doing the job, so had to admit defeat and RTFM, which gave me the answer:

And so I had the answer to my problem. Of course, as I’ve come to expect from man pages, it wasn’t exactly stated right at the beginning, nor in big bold letters that said “By default, grep on OS X uses the basic syntax”. Clearly the people who write man pages take great delight in forcing you to read the description of every damn option to find out what the defaults are. Ironically, I could have found out by using grep, for example:

mangrep|grep-C2" default"

Meh.

Anyway, I had the answer: either place a backslash before the pipe, tell grep to use the extended syntax, or use egrep. Telling grep to use the extended syntax is as simple as using the -E command-line parameter (or –extended-regexp for those who prefer typing a whole essay to get anything done), and so any of these would do the trick: