Skip to content

Instantly share code, notes, and snippets.

@DominikBucher12
Last active September 30, 2018 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikBucher12/844c3417fb1d5264ed1c54632bbe700e to your computer and use it in GitHub Desktop.
Save DominikBucher12/844c3417fb1d5264ed1c54632bbe700e to your computer and use it in GitHub Desktop.
This simple script rotates iOS simulators to given orientation. It can be used for example for UI Testing.
on run argv
set criteria to {"Portrait", "Landscape Left", "Landscape Right", "Portrait Upside Down"}
if (count of argv) = 2 and (item 1 of argv) is in criteria then
set theExpectedWindowCount to item 2 of argv as integer
(* First we start with system event to work on Simulator and set it to foreground...*)
tell application "Simulator" to activate
tell application "System Events" to tell process "Simulator"
set frontmost to true
set counter to 0
(* Then we iterate over windows in the process, simulator variable is here in fact the window *)
log (count of windows) = theExpectedWindowCount (*"Count of windows is " & (count of windows) & " And expected windows count is" & theExpectedWindowCount*)
log "Count of windows is " & (count of windows) & " And expected windows count is" & theExpectedWindowCount
if (count of windows) is not theExpectedWindowCount then
repeat until (count of windows) = theExpectedWindowCount or counter = 10
log theExpectedWindowCount
log "😴 Waitin' "
delay 6
set counter to counter + 1
end repeat
end if
if counter = 10 then
log "❌ Simulator timed out to show all devices, number of devices is " & (count of windows)
error number 1
end if
(* Then we iterate over windows in the process, simulator variable is here in fact the window *)
repeat with simulator from 1 to count windows
(* We set the focus on the simulator window which is next in our iteration *)
get properties of window simulator
set simulatorName to name of window simulator
click menu item simulatorName of menu 1 of menu bar item "Window" of menu bar 1
set focused of window simulator to true
(* And finally we rotate it 🤯 *)
set deviceOrientation to item 1 of argv
click menu item deviceOrientation of menu 1 of menu item "Orientation" of menu 1 of menu bar item "Hardware" of menu bar 1
log "🌀 Rotation was successfull "
end repeat
end tell
else
(* If the rotation is not supported or not given, we throw exception and exit script *)
log "❌ Please specify the orientation of device: \"Portrait\" | \"Landscape Left\" | \"Landscape Right\" | \"Portrait Upside Down\""
error number 1
end if
(*tell application "System Events" to windows of process "Simulator"*)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment