Skip to content

Instantly share code, notes, and snippets.

@benallfree
Created November 6, 2015 14:43
Show Gist options
  • Save benallfree/f2813074a7fca7beb353 to your computer and use it in GitHub Desktop.
Save benallfree/f2813074a7fca7beb353 to your computer and use it in GitHub Desktop.
AppleScript to launch iOS Simulator and Safari debugger using iTerm
#!/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 "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 "iTerm"
activate
set myterm to (current terminal)
tell myterm
set mysession to (last session)
tell mysession
write text "ionic emulate ios"
end tell
end tell
end tell
# in case the app is already open, go back to the home screen
tell application "Simulator"
activate
tell application "System Events" to keystroke "h" using {shift down, command down}
delay 2
end tell
# 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 "debug.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
end if
end tell
tell application "Simulator"
activate
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment