Skip to content

Instantly share code, notes, and snippets.

Forked from Thinkscape/open-webinspector.applescript
Last active December 19, 2018 02:53
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save uniphonic/fc4e679884aa83787c26 to your computer and use it in GitHub Desktop.
This is an AppleScript to automatically compile Cordova and open the Safari debugger. You can also use Automator to assign this script to a shortcut key.
# AppleScript to automatically compile Cordova and open the Safari debugger
set maxWait to 20
set hasClicked to false
set x to 0
set device_name to "iOS Simulator"
# delay fix for yosemite
on delay duration
set endTime to (current date) + duration
repeat while (current date) is less than endTime
tell AppleScript to delay duration
end repeat
end delay
# open terminal if it's not open already
tell application "Terminal"
if not (exists window 1) then reopen
do script "cordova run ios" in window 1
end tell
# in case the app is already open, go back to the home screen
tell application "iOS Simulator"
tell application "System Events" to keystroke "h" using {shift down, command down}
end tell
delay 5
# open safari and wait for the ios app to become available for debugging
tell application "Safari"
repeat until hasClicked or x > (maxWait * 10)
tell application "System Events"
click menu item "index.html" of menu device_name of menu item device_name 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
tell application "System Events"
click button 1 of window "Favorites" of application process "Safari"
end tell
end try
end if
end tell
Copy link

How to make a shortcut key to automatically compile and open the debugger.


  1. On your Mac, open Automator (press command space and type automator and then press enter)
  2. Choose "Service"
  3. In the options at the top of the screen change the "Service receives" to "no input"
  4. In the search box, type AppleScript, then double click on the "Run AppleScript" command
  5. Paste in the AppleScript included in this page
  6. Save it to the name "iOS Compile and Debug"
  7. Close Automator
  8. Open System Preferences > Keyboard > Shortcuts > Services
  9. Scroll to the bottom, under General, and you should see your the new service you created there
  10. Add a shortcut by click in the right column where it says none, and then click again to "add shortcut", and then press the shortcut you desire (e.g. Command Option X)

To use

  1. Make sure your terminal is open to your Cordova project folder.
  2. Press your shortcut keys (e.g. Command Option X)

Copy link

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