Skip to content

Instantly share code, notes, and snippets.

@DominikBucher12
Created October 1, 2018 00:08
Show Gist options
  • Save DominikBucher12/8d680988dc7cc277e275125a0dd16da5 to your computer and use it in GitHub Desktop.
Save DominikBucher12/8d680988dc7cc277e275125a0dd16da5 to your computer and use it in GitHub Desktop.
Presentation_rotation (not binary :( )
on run argv
(*set criteria to {"Portrait", "Landscape Left", "Landscape Right", "Portrait Upside Down"}*)
if (count of argv) = 1 then (*and (item 1 of argv) is in criteria then*)
set theExpectedWindowCount to item 1 of argv as integer
(* First we start with system event to work on Simulator and set it to foreground...*)
tell application "System Events" to tell process "Simulator"
set frontmost to true
set counter to 0
(* Set number of simulators containing Landscape to expected.*)
(* 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 🤯 *)
if (simulatorName contains "Landscape") then
click menu item "Portrait" of menu 1 of menu item "Orientation" of menu 1 of menu bar item "Hardware" of menu bar 1
click menu item "Landscape Left" of menu 1 of menu item "Orientation" of menu 1 of menu bar item "Hardware" of menu bar 1
log "🌀 Rotation was successfull "
end if
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