Detect other app screen and get size of it

Thanks for the idea. I could not find the second screen in the driver.page_source, and Appium Inspector could not detect the second screen. Can’t use selenium as both screens are actually part of a native MacOS app, not browser (I’m using Mac2 driver).

I tried your last suggestion of using AppleScript, and used XCode’s accessibility inspector which managed to detect the second screen as a dialog(which was highlighted in green, I hid app details with black boxes).

I am thinking of using the accessibility role and description shown in Hierarchy to check if the second screen exists in AppleScript, but I don’t know much about AppleScript. Will this approach work?

If anyone is good at apple script, could you advise me on the code below?
For reference, i did come up with a initial code that is throwing syntax error Expected end of line, etc. but found property.:

tell application "MyMacOSApp"
    activate
    delay 1.0
end tell

tell application "System Events"
    tell window of application process "MyMacOSApp"
        tell button "Login" of group "Login"
            click
        end tell
        set dialogWindow to first window whose accessibility role is "AXWindow" and accessibility description is "SecondDialogWindow"
        if dialogWindow exists then
            return true
        else
           return false
        end if
    end tell
end tell

After the apple script works, I can use isSecondScreenPresent = driver.execute_script("macos: appleScript", {"script": apple_script}) to check for the screen