Skip to content

Instantly share code, notes, and snippets.

@shouse
Created November 7, 2017 20:06
Show Gist options
  • Save shouse/7b4bb3ea454790183f7e703232ed0940 to your computer and use it in GitHub Desktop.
Save shouse/7b4bb3ea454790183f7e703232ed0940 to your computer and use it in GitHub Desktop.
Open up Safari's Web Inspector to be used for debugging
#!/bin/sh
function ios-sim-inspector() {
appName="$1"
osascript <<EOF
# Name of the device as visible in Safari->Develop menu
set deviceName to "Simulator"
# Number of seconds to wait for the simulator window to show up
set maxWait to 20
set hasClicked to false
set x to 0
tell application "Safari"
activate
repeat until hasClicked or x > (maxWait * 10)
try
tell application "System Events"
click menu item "$appName" of menu deviceName of menu item deviceName of menu "Develop" of menu bar item "Develop" of menu bar 1 of application process "Safari"
end tell
set hasClicked to true
on error foo
delay 0.1
set x to x + 1
end try
end repeat
if hasClicked = false then
display dialog "Unable to connect to iOS simulator - make sure that it's working" buttons {"OK"} default button 1
else
try
tell application "System Events"
click button 1 of window "Favorites" of application process "Safari"
end tell
end try
return
end if
end tell
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment