Forked from Thinkscape/open-webinspector.applescript
Last active
December 19, 2018 02:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
# 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 | |
activate | |
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" | |
activate | |
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" | |
activate | |
repeat until hasClicked or x > (maxWait * 10) | |
try | |
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to make a shortcut key to automatically compile and open the debugger.
Setup
To use