How to toggle between "Portrait" and "Landscape Right" orientation in iOS simulators via AppleScript?
On my system, using Script Editor, the following example AppleScript code works for me to toggle between Portrait and Landscape Right of the Simulator window:
tell application &quot;Simulator&quot; to activate

tell application &quot;System Events&quot; to ¬
    tell application process &quot;Simulator&quot; to ¬
        tell menu 1 of ¬
            menu item &quot;Orientation&quot; of ¬
            menu 1 of ¬
            menu bar item &quot;Device&quot; of ¬
            menu bar 1
            if value of ¬
                attribute &quot;AXMenuItemMarkChar&quot; of ¬
                menu item &quot;Portrait&quot; is &quot;✓&quot; then
                click menu item &quot;Landscape Right&quot;
            else if value of ¬
                attribute &quot;AXMenuItemMarkChar&quot; of ¬
                menu item &quot;Landscape Right&quot; is &quot;✓&quot; then
                click menu item &quot;Portrait&quot;
            end if
        end tell


Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.