Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Forked from amuino/webinspector.applescript
Last active September 8, 2020 01:34
  • Star 17 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Thinkscape/8538321 to your computer and use it in GitHub Desktop.
Script for opening web inspector window for remote debugging iOS web apps (including phonegap and other webview apps). This version of the script will suspend and wait for 30 seconds for Safari to establish a connection with the device (or simulator) and open the web inspector window as soon as technically possible.
#!/usr/bin/osascript
# Name of the device as visible in Safari->Develop menu
set deviceName to "iPhone Simulator"
# Number of seconds to wait for the simulator window to show up
set maxWait to 30
# ---------------------------------------
# You shouldn't modify anything below here
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 "index.html" of menu deviceName of menu item deviceName of menu "Develop" of menu bar item $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 "Top Sites" of application process "Safari"
end tell
end try
return
end if
end tell
@alphacat2018
Copy link

alphacat2018 commented Nov 16, 2018

I made an Alfred workflow for this. - https://github.com/alphacat2018/AlfredOpenSafariInspector

@doug-sheridan
Copy link

If you can't get @alphacat2018's suggestion to work, try using this other Workflow with Alfred:
https://github.com/dcalhoun/alfred-remote-inspector-workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment