Created
January 20, 2020 20:09
-
-
Save Geczy/af06ebacd14b47d7d595cc0efbb7702a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
ios-sim-inspector() { | |
if [ $# -eq 0 ]; then | |
printf "\n Usage: $ ios-sim-inspector <index-page-title> <device-name>\n\n" | |
printf " * <index-page-title> cannot have the same name as the folder containing it :(\n\n" | |
else | |
appName="$1" | |
# Safari has been very stubborn about reloading "Develop" menu | |
# so, we force it to quit first :( | |
killall Safari | |
osascript <<EOF | |
# Name of the device as visible in Safari->Develop menu | |
set deviceName to "$2" | |
# Number of seconds to wait for the simulator window to show up | |
set maxWait to 10 | |
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 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment